So, what im trying to do is 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 error.. how can I use certain numbers in an array and put them into an equation?
4 Answers
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)
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.
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
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