"TypeError: can't multiply sequence by non-int of type 'float'" when doing a numpy dot product
"TypeError: can't multiply sequence by non-int of type 'float'" when doing a numpy dot product
我目前正在尝试学习在 python 中从头开始编写神经网络代码,但在尝试编写矩阵“layer2_outputs”时遇到以下错误。到目前为止,这是我的代码:
inputs = [[1, 2, 3, 2.5],
[2.0, 5.0, -1.0, 2.0],
[-1.5, 2.7, 3.3, -0.8]]
weights = [[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
biases = [2, 3, 0.5]
weights2 = [[0.1, -0,14, 0.5],
[-0.5, 0.12, -0.33],
[-0.44, 0.73, -0.13]]
biases2 = [-1, 2, -0.5]
layer1_outputs = np.dot(inputs, np.array(weights).T) + biases
layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2
print(layer2_outputs)
我已经尝试查找错误消息,但我无法找到解决问题的方法,所以如果你们中有人能帮助我,我会非常高兴并且如果您需要任何其他信息,请问我,我是 Stack Overflow 的新手,所以不要太苛刻哈哈 :)
这是准确的错误消息,以防万一:
> VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a
list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated.
If you meant to do this, you must specify 'dtype=object' when creating the ndarray
layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2
Traceback (most recent call last):
File "c:\Users\[myName]\Desktop\firstneuralnetwork.py", line 20, in <module>
**layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2**
File "<__array_function__ internals>", line 5, in dot
**TypeError: can't multiply sequence by non-int of type 'float'**
-0,14 在 weights2
中应该是 -0.14
错误消息的第一行表示您正在尝试构建一个非矩形的 np 数组,这是不允许的
我目前正在尝试学习在 python 中从头开始编写神经网络代码,但在尝试编写矩阵“layer2_outputs”时遇到以下错误。到目前为止,这是我的代码:
inputs = [[1, 2, 3, 2.5],
[2.0, 5.0, -1.0, 2.0],
[-1.5, 2.7, 3.3, -0.8]]
weights = [[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
biases = [2, 3, 0.5]
weights2 = [[0.1, -0,14, 0.5],
[-0.5, 0.12, -0.33],
[-0.44, 0.73, -0.13]]
biases2 = [-1, 2, -0.5]
layer1_outputs = np.dot(inputs, np.array(weights).T) + biases
layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2
print(layer2_outputs)
我已经尝试查找错误消息,但我无法找到解决问题的方法,所以如果你们中有人能帮助我,我会非常高兴并且如果您需要任何其他信息,请问我,我是 Stack Overflow 的新手,所以不要太苛刻哈哈 :)
这是准确的错误消息,以防万一:
> VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a
list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated.
If you meant to do this, you must specify 'dtype=object' when creating the ndarray
layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2
Traceback (most recent call last):
File "c:\Users\[myName]\Desktop\firstneuralnetwork.py", line 20, in <module>
**layer2_outputs = np.dot(layer1_outputs, np.array(weights2)) + biases2**
File "<__array_function__ internals>", line 5, in dot
**TypeError: can't multiply sequence by non-int of type 'float'**
-0,14 在 weights2
中应该是 -0.14错误消息的第一行表示您正在尝试构建一个非矩形的 np 数组,这是不允许的