TypeError:'numpy.float64'对象不可调用

use*_*265 6 python numpy

因此,我想要做的是从给定>范围的数组中的某些位置获取某些数字并将它们放入等式中

yy = arange(4)
xx = arange(5)
Area = ((xx[2] - xx[1])(yy[2] + yy[1])) / 2
Run Code Online (Sandbox Code Playgroud)

我尝试运行它,我得到了..

----> ((xx[2] - xx[1])(yy[2] + yy[1])) / 2
TypeError: 'numpy.int64' object is not callable
Run Code Online (Sandbox Code Playgroud)

我得到错误..如何在数组中使用某些数字并将它们放入等式中?

Ign*_*ams 19

Python不遵循与书面数学相同的规则.您必须明确指出乘法.

坏:

(a)(b)
Run Code Online (Sandbox Code Playgroud)

(除非a是功能)

好:

(a) * (b)
Run Code Online (Sandbox Code Playgroud)


mrk*_*mrk 12

当您的函数与返回值同名时也会发生此错误

def samename(a, b):
    samename = a*b
    return samename
Run Code Online (Sandbox Code Playgroud)

这可能是一个超级菜鸟的错误,我很好奇这个答案多久会有帮助。

  • python 5年了,刚刚犯了这个错误...在尝试解决它时发现这个答案很有帮助... (2认同)

Aka*_*all 8

*在乘法时你会失踪,试试:

import numpy as np
yy = np.arange(4)
xx = np.arange(5)
Area = ((xx[2] - xx[1])*(yy[2] + yy[1])) / 2
Run Code Online (Sandbox Code Playgroud)


小智 5

发生这种情况的原因可能是您覆盖了尝试调用的函数的名称。

例如:

def x():
    print("hello world")
...
x = 10.5
...
x()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in 
      2     print("hello world")
      3 x = 10.5
----> 4 x()

TypeError: 'float' object is not callable
Run Code Online (Sandbox Code Playgroud)