簡單的邏輯電路
阿新 • • 發佈:2018-09-28
arr num def code else -- import sum 權重
簡單的與門、與非門、或門
import numpy as np
def AND(x1,x2):
x = np.array([x1,x2]) #輸入
w = np.array([0.5,0.5]) #權重
b = -0.7 #偏置
tmp = np.sum(w*x)+b
if tmp <= 0:
return 0
else:
return 1
print(AND(0,0))
print(AND(1,0))
print(AND(0,1))
print(AND(1,1))
print(‘--------------------‘)
def NAND(x1,x2):
x = np.array([x1,x2]) #輸入
w = np.array([-0.5,-0.5]) #權重
b = 0.7 #偏置
tmp = np.sum(w*x)+b
if tmp <= 0:
return 0
else:
return 1
print(NAND(0,0))
print(NAND(1,0))
print(NAND(0,1))
print(NAND(1,1))
print(‘--------------------‘)
def OR(x1,x2):
x = np.array([x1,x2]) #輸入
w = np.array([-0.5,-0.5]) #權重
b = -0.2 #偏置
tmp = np.sum(w*x)+b
if tmp <= 0:
return 0
else:
return 1
print(OR(0,0))
print(OR(1,0))
print(OR(0,1))
print(OR(1,1))
簡單的邏輯電路