ValueError: could not broadcast input array from shape (10) into shape (1)
运行python程序时遇到上述问题,错误定位到下面的代码片
hide_out[j] = sigmoid(hide_in[j])
代码中相关内容的定义如下
hidesize = 10
W1 = np.random.random((hidesize,1)) #输入层与隐层之间的权重
B1 = np.random.random((hidesize,1)) #隐含层神经元的阈值
for i in range(x_size):
hide_in = np.dot(x[i],W1)-B1 # 隐含层输入数据
#print(x[i])
hide_out = np.zeros((hidesize,1)) #隐含层的输出数据``
**解决办法:**
出问题代码片改为如下的代码
hide_out[j][0] = sigmoid(hide_in[j][0])
类似的还有
dB1[j] = np.dot(np.dot(W2[0][j],sigmoid(hide_in[j])),(1-sigmoid(hide_in[j]))*(-1)*e*threshold)
改为
dB1[j] = np.dot(np.dot(W2[0][j], sigmoid(hide_in[j][0])), (1 - sigmoid(hide_in[j][0])) * (-1) * e * threshold)
|