TypeError Traceback (most recent call last) TypeError: only size-1 arrays can be converted to Python scalars The above exception was the direct cause of the following exception: ValueError Traceback (most recent call last) Cell In[1], line 55 52 ary_target = [0.5, 0.5] 54 for i in range(1000): ---> 55 ary_w, ary_b = train(ary_input, ary_w, ary_b, ary_target) 57 print("Updated weights:", ary_w) Cell In[1], line 19, in train(ary_input, ary_w, ary_b, ary_target, learning_rate) 17 ary_hidden_net[i] = 0 18 for j in range(n): ---> 19 ary_hidden_net[i] += ary_w[i][j] * ary_input[j] 20 ary_hidden_net[i] += ary_b[0] 21 ary_hidden_out[i] = sigmod(ary_hidden_net[i]) ValueError: setting an array element with a sequence.
时间: 2024-01-28 07:05:50 浏览: 162
TypeError: only integer tensors of a single element can be converted to an index
这个错误是因为在训练函数中的第19行,你尝试将一个大小为2的数组(ary_input)乘以一个大小为2x2的数组(ary_w),这是不允许的。你需要确保ary_input和ary_w具有相同的维度。你可以使用np.dot函数来执行矩阵乘法,以确保这一点。例如,你可以将第19行修改为:
```
ary_hidden_net[i] += np.dot(ary_w[i], ary_input)
```
阅读全文