While doing data normalization, I always get ValueError: cannot convert float NaN to integer

Numpy floats allow NaN values but ints don’t. So the NaN propagates through your float calculations until it hits the int conversion.

That is, you are reading the data which results in some NaN values, then max returns a NaN for these rows, and the same for abs also return NaN, then int() complains.

Try:

data = np.array(data, dtype=np.float32) # from your code
print(np.argwhere(np.isnan(data)))

to find where your NaN values are.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top