Python NumPy: How to Resolve "TypeError: 'numpy.float64' object is not callable" in Python
When working with NumPy, you may encounter the error TypeError: 'numpy.float64' object is not callable (or its variant TypeError: 'numpy.ndarray' object is not callable). This error occurs when you accidentally try to call a NumPy value or array as if it were a function by putting parentheses () after it.
In this guide, we'll explain why this happens, show the common scenarios that trigger it, and walk through how to fix each one.
Why Does This Error Occur?
In Python, parentheses () after a name mean "call this as a function." When you put parentheses after a NumPy float or array - which is a data value, not a function - Python tries to "call" it and raises a TypeError because data values aren't callable.
❌ Example that triggers the error:
import numpy as np
value = np.float64(3.14)
result = value() # Trying to "call" a float value
Output:
TypeError: 'numpy.float64' object is not callable
Python sees value() and tries to execute value as a function, but np.float64(3.14) is a number, not a function.
Common Scenarios and Fixes
Scenario 1: Accidentally Adding Parentheses After an Array
The most basic case - putting () after an array or value by mistake:
❌ Wrong:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr()) # Parentheses make Python try to "call" the array
Output:
TypeError: 'numpy.ndarray' object is not callable
✅ Correct - Remove the parentheses:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr) # No parentheses, just reference the array
Output:
[1 2 3 4 5]
If you want to access elements of an array, use square brackets [], not parentheses ():
arr = np.array([10, 20, 30])
print(arr[0]) # ✅ Correct: 10
print(arr(0)) # ❌ Error: trying to call arr as a function
Scenario 2: Overwriting a Function Name with a Variable
This is the most common and subtle cause. If you accidentally assign a value to a name that was previously a function, the function gets replaced by the value, and subsequent calls to that name fail:
❌ Wrong - Overwriting sum with its result:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
# First call works fine
sum = np.sum(arr) # sum is now 15 (numpy.int64), not the function!
print(sum)
# Second call fails because 'sum' is now a number, not a function
result = sum(arr) # TypeError!
Output:
15
TypeError: 'numpy.int64' object is not callable
✅ Correct - Use a different variable name:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
total = np.sum(arr) # Use 'total' instead of 'sum'
print(total)
# np.sum still works because we didn't overwrite it
result = np.sum(arr * 2)
print(result)
Output:
15
30
Never use these as variable names because they shadow built-in functions or NumPy functions:
| ❌ Avoid | Why | ✅ Use Instead |
|---|---|---|
sum | Shadows sum() and np.sum() | total, arr_sum |
max | Shadows max() and np.max() | maximum, max_val |
min | Shadows min() and np.min() | minimum, min_val |
mean | Shadows np.mean() | avg, mean_val |
array | Shadows np.array() | arr, data |
float | Shadows float() | value, result |
round | Shadows round() | rounded, round_val |
Scenario 3: Overwriting a Function in a Loop
This often happens when you compute a value inside a loop and accidentally reuse the function name:
❌ Wrong - Overwriting mean in a loop:
import numpy as np
datasets = [
np.array([1, 2, 3]),
np.array([4, 5, 6]),
np.array([7, 8, 9]),
]
mean = np.mean # Reference to the function
for data in datasets:
mean = mean(data) # First iteration: works. Second iteration: TypeError!
print(mean)
Output:
2.0
TypeError: 'numpy.float64' object is not callable
After the first iteration, mean becomes 2.0 (a float), and the second iteration tries to call 2.0(data).
✅ Correct - Use a different variable name for the result:
import numpy as np
datasets = [
np.array([1, 2, 3]),
np.array([4, 5, 6]),
np.array([7, 8, 9]),
]
for data in datasets:
avg = np.mean(data) # 'avg' for the result, 'np.mean' stays a function
print(avg)
Output:
2.0
5.0
8.0
Scenario 4: Using Parentheses Instead of Brackets for Indexing
NumPy arrays use square brackets [] for indexing, not parentheses ():
❌ Wrong - Parentheses for indexing:
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
print(arr(2)) # Trying to call the array as a function
Output:
TypeError: 'numpy.ndarray' object is not callable
✅ Correct - Square brackets for indexing:
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
print(arr[2]) # Single element
print(arr[1:4]) # Slice
Output:
30
[20 30 40]
Scenario 5: Mathematical Expressions Missing an Operator
In mathematics, 2(3) means 2 × 3. In Python, 2(3) means "call 2 as a function with argument 3":
❌ Wrong - Implied multiplication:
import numpy as np
x = np.float64(5.0)
result = 2(x) # Python sees this as calling 2 as a function
Output:
TypeError: 'int' object is not callable
Similarly with NumPy values:
a = np.float64(2.0)
b = np.float64(3.0)
result = a(b) # Trying to call a as a function
✅ Correct - Use explicit multiplication operator:
import numpy as np
x = np.float64(5.0)
result = 2 * x
print(result)
a = np.float64(2.0)
b = np.float64(3.0)
result = a * b
print(result)
Output:
10.0
6.0
How to Debug This Error
When you see this error, follow these steps:
-
Step 1: Find the line that causes the error (from the traceback).
-
Step 2: Look for parentheses
()after a variable that should be data, not a function. -
Step 3: Check if you've overwritten a function name:
import numpy as np
# Check what a name currently refers to
print(type(sum)) # Should be <class 'builtin_function_or_method'>
print(type(np.mean)) # Should be <class 'function'>If
type(sum)showsnumpy.int64ornumpy.float64, you've overwritten the built-insumfunction. -
Step 4: In Jupyter Notebook, restart the kernel to reset any overwritten names, then re-run your cells.
In Jupyter, it's easy to accidentally overwrite a function in one cell and not realize it when running a later cell. If you get this error unexpectedly, restart the kernel (Kernel → Restart & Run All) to ensure a clean state.
Quick Reference
| Cause | Fix |
|---|---|
arr() instead of arr | Remove the parentheses |
arr(0) instead of arr[0] | Use square brackets for indexing |
sum = np.sum(arr) then sum(other) | Use a different variable name (total) |
2(x) instead of 2 * x | Use explicit * operator |
| Function overwritten in a loop | Use different names for functions and results |
Conclusion
The TypeError: 'numpy.float64' object is not callable error occurs when you accidentally use parentheses () after a NumPy value or array, which tells Python to try to execute it as a function.
- The most common cause is overwriting a function name (like
sum,mean, ormax) with a computed result, making the function name point to a number instead. - The fix is straightforward: use different variable names for results (e.g.,
totalinstead ofsum), use square brackets[]for array indexing, and use explicit operators (*,+) instead of implied mathematical notation.