Reputation: 211
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?
Upvotes: 21
Views: 203119
Reputation: 126
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
Upvotes: 5
Reputation: 10406
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.
Upvotes: 29
Reputation: 86306
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
Upvotes: 11
Reputation: 799230
Python does not follow the same rules as written math. You must explicitly indicate multiplication.
(a)(b)
(unless a
is a function)
(a) * (b)
Upvotes: 33