每次运行它时,我都会得到TypeError
告诉我操作数不支持Floats和Methods。我能不能让我知道我做错了什么以及如何解决这个问题?
from numpy import random,array,dot
class neural():
def __init__(self):
self.weights=2*random.random(3).reshape((3,1))-1
def __sigmoid(self,x):
return 1/(1+exp(-x))
def predict(self,inputs):
print("called predict function successfully")
#pass inputs through our neural network (our single neuron)
return dot(input,self.weights)
if __name__=="__main__":
nn=neural()
print(nn.weights)
print(nn.predict(array([3,1,1])))
包括Traceback在内的例外是:
12 nn=neural()
13 print(nn.weights)
---> 14 print(nn.predict(array([3,1,1])))
8 print("called predict function successfully")
9 #pass inputs through our neural network (our single neuron)
---> 10 return dot(input,self.weights)
TypeError: unsupported operand type(s) for *: 'method' and 'float'
答案 0 :(得分:3)
应该是:
return dot(inputs, self.weights)
不
return dot(input, self.weights)
input
是内置函数,而inputs
是函数的参数。哪个应该解释异常。