Home > OS >  float' object cannot be interpreted as an integer for array
float' object cannot be interpreted as an integer for array

Time:10-24

this si the code I have below

import matplotlib.pyplot as plt
import numpy as np
fig, ax1 = plt.subplots()
z = np.linspace(0.20, 0.30, 0.01)

and the error I get TypeError: 'float' object cannot be interpreted as an integer how to fix this

CodePudding user response:

As it is explained in the NumPy documentation, number of samples between the two limits must be specified, not the increments. i.e. the code must be as:

z = np.linspace(0.20, 0.30, num=11)

CodePudding user response:

The last argument of the np.linspace function is the count of elements to be generated which should be an integer and not a float value.

  • Related