import numpy as np
defAND(x1,x2):
w = np.array([0.5,0.5])
x = np.array([x1,x2])
b =-0.7
tmp = np.sum(w*x)+b
if tmp <=0:return0elif tmp >0:return1#0 0 0 1
import numpy as np
defNAND(x1,x2):
w = np.array([-0.5,-0.5])#仅权重和偏置改变了
x = np.array([x1,x2])
b =0.7
tmp = np.sum(w*x)+b
if tmp <=0:return0elif tmp >0:return1defOR(x1, x2):
x = np.array([x1, x2])
w = np.array([0.5,0.5])# 仅权重和偏置与AND不同!
b =-0.2
tmp = np.sum(w*x)+ b
if tmp <=0:return0else:return1# 1 1 1 0# 0 1 1 1