python - “TypeError:在进行 numpy 点积时,不能将序列乘以‘float’类型的非整数”
问题描述
我目前正在尝试学习在 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 应为 -0.14 权重2
错误消息的第一行表示您正在尝试构建一个不是矩形的 np 数组,这是不允许的
推荐阅读
- javascript - 遍历 json 并获取每个 xth 对象值
- c++ - 如何让机器人在检测到障碍物时停止(C++、Raspberry PI、TCP 通信)
- javascript - 为什么我在动态渲染 html 时不能将对象作为函数参数传递?
- android - 使用python在windows中模拟Android
- javascript - 在 WooCommerce 中付款后用于更新库存的挂钩是什么?
- c - 在 GTK3 中在屏幕上绘制自定义内容的替代方法?
- python - 如何拆分抓取的数据并将其作为带有完整链接和描述的 csv 保存在单独的列中?
- php - PHP 和 XmlWriter 更改缩进字符串
- excel - 一旦标题行满足特定条件,如何沿列创建循环然后循环到下一行
- java - 来自 PHP 的 Java 中的 AES-Rijndael 128 加密