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

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

by Erma Khan

One error you may encounter when using Python is:

TypeError: 'numpy.float64' object is not callable

This error may occur in two different scenarios:

  • Scenario 1: Multiplication Without Using * Sign
  • Scenario 2: Failure to Use NumPy Min Function

The following examples shows how to fix this error in each scenario.

Scenario 1: Multiplication Without Using * Sign

Suppose we attempt to multiply two NumPy arrays without using a multiplication sign (*) as follows:

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
combo = (x)(y)

#view result
print(combo)

TypeError: 'numpy.float64' object is not callable 

We receive a TypeError because we didn’t use the multiplication sign (*) when attempting to multiply the two arrays.

The way to avoid this error is to make sure we used the multiplication sign:

import numpy as np

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

#multiply two arrays together
combo = (x)*(y)

#view result
print(combo)

[ 12  28  42  76 110]

Notice that we receive no error this time.

Scenario 2: Failure to Use NumPy Min Function

Suppose we use the following code to attempt to find the minimum value of a NumPy array:

import numpy as np

#define array of data
data = np.array([3.3, 4.1, 4, 5.6, 8.1, 9.9, 9.7, 10.2])

#attempt to find minimum value of array
min_val = min(data)

#view minimum value
print(min_val)

TypeError: 'numpy.float64' object is not callable 

We receive a TypeError because we used the min() function.

Instead, we need to use np.min() as follows:

import numpy as np

#define array of data
data = np.array([3.3, 4.1, 4, 5.6, 8.1, 9.9, 9.7, 10.2])

#attempt to find minimum value of array
min_val = np.min(data)

#view minimum value
print(min_val)

3.3

Notice that we receive no error this time.

Additional Resources

The following tutorials explain how to fix other common errors in Python:

How to Fix: columns overlap but no suffix specified
How to Fix: ‘numpy.ndarray’ object has no attribute ‘append’
How to Fix: if using all scalar values, you must pass an index
How to Fix: ValueError: cannot convert float NaN to integer

Related Posts