python - 为什么这个列表:[[-0.23684 -2.54357006 1.06844643]] 返回为无类型?查看代码输出
问题描述
当执行下面列出的输出命令 (1.) 时,您可以看到有一个列表输出:[[0.1357893 0.13558951 0.13562417]],当命令 (5.) 询问此输出的类型时,它输出为 class <'None键入'>。所以问题是为什么这个非空列表被称为无类型。你可以看到没有错误输出。
您还可以确认输出 (2.) 是否是数组列表,这就是它列出类型的原因。
1.Network.feed forward ([1,5])
2.print(网络权重)
3.print(Network.biases)
4.print(类型(网络权重))
5.print(类型(网络。前馈([1,5])))
6.print(长度(Network.weights))
它给出了如下所述的输出
1.[[0.1357893 0.13558951 0.13562417]]
2. [array([[ 1.17769878, 1.09506853],
[ 1.13799858, 2.71622618],
[-0.35448734, 1.75165491]]), array([[-1.56395246, 0.83951109,
-0.27785569]])]
3.[array([[0.02232141],
[0.65477376],
[0.19102921]]), array([[-0.85011921]])]
4.<class 'list'>
为什么会这样输出?[[0.13618594 0.1355904 0.13578948]]
5.<class 'NoneType'>
6.2
进程以退出代码 0 结束
这是相关代码:
import numpy as np
class Network(object):
def __init__(self, sizes):
"""The list ``sizes`` contains the number of neurons in the
respective layers of the network. """
self.num_layers = len(sizes)
self.sizes = sizes
self.biases = [np.random.randn(y, 1) for y in sizes[1:]]
self.weights = [np.random.randn(y, x)
for x, y in zip(sizes[:-1], sizes[1:])]
def feedforward(self, a):
"""Return the output of the network if ``a`` is input."""
for b, w in zip(self.biases, self.weights):
a = np.dot(w, a)+b
print(a)
Network = Network([2,3,1])
Network.feedforward([1,5])
print(Network.weights)
print(Network.biases)
print(type(Network.weights))
print(type(Network.feedforward([1,5])))
print(len(Network.weights))
解决方案
Network.feedforward([1,5])
不返回任何东西。
您需要在函数return
末尾添加一条语句feedforward
,因为feedforward
编辑您给它但返回的数组None
。
推荐阅读
- node.js - Joi 验证功能
- java - 如何将字符串转换为 ECDH PublicKey 并检查其连接性
- c# - 将设置从 .bot 文件迁移到 appsettings 时如何修复机器人配置
- php - 归并排序时为什么会出现堆栈溢出?
- python-3.x - 我在源文件夹中有 100 个 xml 文件,我想使用 python 将这些文件移动到 3 个不同的目标文件夹
- python - 在 colab 中导入 gensim 包时出错
- hyperledger-fabric - 打包链码
- php - 如何将 Rate Yo 添加到数据库中
- mongodb - 何时从流中清除 mongodb 更改流事件
- unit-testing - 在 Kotlin (Corda) 中运行合同单元测试时出现 IllegalArgumentException