Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

python - TypeError: Cannot interpret '4' as a data type

I am trying to learn Neural Network. Following is the code. I am getting the error 'TypeError: Cannot interpret '4' as a data type" Can anyone please help me identifying the mistake?

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Per function description

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

The 2nd parameter should be data type and not a number


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...