i am writing python program that implements the NAND gate, it calculates the weight 20 times for the algorithm. but I'm getting an error
"ValueError: operands could not be broadcast together with shapes (4,) (3,)"
on the line where i am calculating the weight.
%matplotlib inline
import numpy as np
import matplotlib.pylab as plt
learningRate=0.2
epochs=5
n_inputs = 2
w=np.zeros(n_inputs+1)
training_inputs=np.array([[1, 0, 0], [1, 0, 1], [1, 1, 0],[1, 1, 1]])
d=np.array([[1,1,1,-1]])
for j in range(epochs):
for inputs, targets in zip(training_inputs, d):
sum=np.dot(inputs, w)
if sum>0:
activation = 1;
elif sum == 0:
activation = 0;
else:
activation = -1;
w =w+learningRate*(targets-activation)*inputs
print("weight= ",w)
fig = plt.figure();
ax=fig.add_subplot(1,1,1)
x = np.linspace(0,2.)
ax.scatter(training_inputs[:,1],training_inputs[:,2])
ax.plot(x, ((x*w[1]+w[0])/-w[2]))