Reputation: 49
Hello I have the following script:
import numpy as np
import matplotlib.pyplot as plt
m = int(input("lenght of t and b. m = "))
t = 27 * np.random.random( (m, 1) )
b = 27 * np.random.random( (m, 1) )
A = np.ones( (m, 1) )
A = np.hstack( (A, t) )
x = np.linalg.solve( np.dot(A.T, A), np.dot(A.T, b) )
print("x = \n", x)
t1 = np.linspace ( min(t), max(t), 50)
b1 = np.polyval(x[::-1, t1])
plt.plot(t1, b1)
plt.plot(t, b, "ro")
plt.xlabel("t")
plt.ylabel("b")
plt.show()
I'm trying to do a plot but i'm getting the following error "IndexError: arrays used as indices must be of integer (or boolean) type" At the line:
b1 = np.polyval(x[::-1, t1])
How can I solve this please?
Upvotes: 0
Views: 787
Reputation: 1174
This error may also happen when the DataFrame or numpy array has NaN values. It can be fixed like this:
df.fillna(0)
Or any other suitable fillna()
strategy
Upvotes: 1