19

So, what I'm trying to do is to 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 an error.. How can I use certain numbers in an array and put them into an equation?

4 Answers 4

33

Python does not follow the same rules as written math. You must explicitly indicate multiplication.

Bad:

(a)(b)

(unless a is a function)

Good:

(a) * (b)
28

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.

1
  • 2
    python for 5 years and just made this mistake...found this answer helpful when trying to resolve it...
    – kibitzforu
    Commented Jan 10, 2022 at 3:08
11

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
5

This could happen because you have overwritten the name of the function that you attempt to call.

For example:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.