Python 类型错误:“numpy.float64”对象不可调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19828212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: 'numpy.float64' object is not callable
提问by user2963265
So, what im trying to do is get certain numbers from certain positions in a array of a given > range and put them into an equation
所以,我试图做的是从给定 > 范围的数组中的某些位置获取某些数字并将它们放入一个方程中
yy = arange(4)
xx = arange(5)
Area = ((xx[2] - xx[1])(yy[2] + yy[1])) / 2
I try to run it and I get this..
我试着运行它,我得到了这个..
----> ((xx[2] - xx[1])(yy[2] + yy[1])) / 2
TypeError: 'numpy.int64' object is not callable
I get error.. how can I use certain numbers in an array and put them into an equation?
我得到错误.. 我怎样才能在数组中使用某些数字并将它们放入一个方程中?
回答by Ignacio Vazquez-Abrams
Python does not follow the same rules as written math. You must explicitly indicate multiplication.
Python 不遵循与书面数学相同的规则。您必须明确指出乘法。
Bad:
坏的:
(a)(b)
(unless a
is a function)
(除非a
是一个函数)
Good:
好的:
(a) * (b)
回答by Akavall
You are missing *
when multiplying, try:
您*
在乘法时丢失了,请尝试:
import numpy as np
yy = np.arange(4)
xx = np.arange(5)
Area = ((xx[2] - xx[1])*(yy[2] + yy[1])) / 2
回答by mrk
This error also occurs when your function has the same name as your return value
当您的函数与返回值同名时也会发生此错误
def samename(a, b):
samename = a*b
return samename
This might be a super rookie mistake, I am curious how often this answer will be helpful.
这可能是一个超级菜鸟的错误,我很好奇这个答案有多少帮助。