21

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)
Sign up to request clarification or add additional context in comments.

Comments

29

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 Comment

python for 5 years and just made this mistake...found this answer helpful when trying to resolve it...
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

Comments

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.