【问题标题】:TypeError: 'numpy.float64' object is not callableTypeError:“numpy.float64”对象不可调用
【发布时间】:2020-06-17 03:37:59
【问题描述】:

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

yy = arange(4)
xx = arange(5)
Area = ((xx[2] - xx[1])(yy[2] + yy[1])) / 2

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

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

我出错了。如何在数组中使用某些数字并将它们放入等式中?

【问题讨论】:

    标签: python numpy


    【解决方案1】:

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

    不好:

    (a)(b)
    

    (除非 a 是一个函数)

    好:

    (a) * (b)
    

    【讨论】:

      【解决方案2】:

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

      def samename(a, b):
          samename = a*b
          return samename
      

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

      【讨论】:

      • python 5 年了,只是犯了这个错误......在尝试解决它时发现这个答案很有帮助......
      【解决方案3】:

      你在乘法时缺少*,试试:

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

      【讨论】:

        【解决方案4】:

        这可能是因为您覆盖了您尝试调用的函数的名称。

        例如:

        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-06-22
          • 2020-09-11
          • 2020-07-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多