How to Fix TypeError: ‘numpy.float64’ object is not callable

TypeError: ‘numpy.float64’ object is not callable error typically occurs in Python when you use the “multiplication without using * sign” or overwrite the sum() function with a numpy.float64 object.

Reason 1: Multiplication without using * sign

import numpy as np

# Define arrays
x = np.array([1, 2, 3, 4, 5])
y = np.array([12, 14, 14, 19, 22])

# Attempt to multiply two arrays together
mul = (x)(y)

# View result
print(mul)

Output

TypeError: 'numpy.ndarray' object is not callable

How to fix it?

import numpy as np

# Define arrays
x = np.array([11, 21, 19, 18, 46])
y = np.array([1, 2, 3, 4, 5])

# Attempt to multiply two arrays together
mul = (x)*(y)

# View result
print(mul)

Output

[ 11 42 57 72 230]

Reason 2: Overwrite the sum() function with a numpy.float64 object

In this approach, errors will occur when you overwrite the built-in sum() function with a numpy.float64 object. Thus, when you later try to use the sum function to add up the numbers in the list, you get the error since numpy.float64 is not callable.

import numpy as np

sum = np.float64(10.5)

result = sum([1, 2, 3])

print(result)

Output

TypeError: 'numpy.float64' object is not callable

How to fix it?

To fix this, you can simply rename the sum variable to something else:

import numpy as np

my_sum = np.float64(10.5) # Rename the variable

result = sum([1, 2, 3]) # Now this uses the built-in sum function

print(result)

Output

6

Always be cautious about overwriting built-in function names. It’s a good practice to avoid using names that are the same as built-in functions or methods.

Related posts

How to Fix ‘numpy.ndarray’ object is not callable

How to Fix ‘numpy.float64’ object cannot be interpreted as an integer

How to Fix numpy.linalg.linalgerror: singular matrix

1 thought on “How to Fix TypeError: ‘numpy.float64’ object is not callable”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.