【问题标题】:TypeError: Cannot interpret '4' as a data typeTypeError:无法将“4”解释为数据类型
【发布时间】:2021-04-17 04:41:08
【问题描述】:

我正在尝试学习神经网络。以下是代码。我收到错误“TypeError:无法将 '4' 解释为数据类型”,谁能帮我找出错误?

import numpy as np

inputs = [[1, 2 , 3, 2.5],
      [2, 5, 9, 10],
      [5, 1, 2, 7],
      [3, 2, 1, 4],
      [1,1.5, 7, 8]]

class layer_dense:
      def __init__ (self, n_inputs, m_neurons):
        self.weights= np.random.rand(n_inputs, m_neurons)
        self.biases= np.zeros(1, m_neurons)
     def forward (self, inputs):
        self.output= np.dot(inputs, self.weights)+self.biases
    
layer1 = layer_dense(4, 4)
layer2 = layer_dense(5,2)

layer1.forward(inputs)
layer2.forward(layer1.output)
print(layer2.output)

【问题讨论】:

    标签: python numpy neural-network conv-neural-network forward


    【解决方案1】:

    Per function description

    numpy.zeros(shape, dtype=float, order='C')
    

    第二个参数应该是数据类型而不是数字

    【讨论】:

      【解决方案2】:

      零的签名如下:

      numpy.zeros(shape, dtype=float, order='C')
      

      shape 参数应以整数或多个整数的元组形式提供。您得到的错误是由于 4 被解释为 dtype。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-19
        • 2017-08-06
        • 1970-01-01
        相关资源
        最近更新 更多