‘numpy.ndarray’ object is not callable – Python Error

So you are getting this numpy python error ‘numpy.ndarray’ object is not callable. Right? This is because somewhere in your code you are using a non-function element like int, array, object, list etc. as function. For example –

Suppose, you have an array – myArray = [2, 3, 4] . Now to access the first element, you should use myArray[0]. But sometimes we mistakenly use myArray(0).

import numpy as np
data = np.array([[1, 2], [3, 4]])
xy = data
for XY in xy:
   i=0  
   Z=XY(i,0)+XY(i,1)
   i=i+1      
   print (Z)

This will throw error, ‘numpy.ndarray‘ object is not callable, because XY is the vector not function. And we are fetching the value, not by index but by passing parameter to it. So, XY(i, 0) is the wrong way. The correct way is XY[0] and XY[1].

Now, let’s correct our above code snippet –

import numpy as np
data = np.array([[1, 2], [3, 4]])
xy = data
for XY in xy:
   i=0  
   Z=XY[0]+XY[1]
   i=i+1      
   print (Z)

The major reason for this error is the conflict of user defined variable names with system functions. For example, you define an integer variable round and try to use math function round. Python will throw error, “Object is not callable”

    Tweet this to help others