I'm trying to use a boolean mask to address rows in a numpy array:
isnan = np.isnan(self.X[:, AGE_COLUMN].astype(float))
self.X[isnan, AGE_COLUMN] = np.mean(self.X[:, AGE_COLUMN].astype(float))
isnan and X are dtype
.
First I check which rows in the age column are nan. And then I want to set these values to the mean of all ages. The debugger has following result for self.X[isnan, AGE_COLUMN]
:
[nan nan nan nan nan nan nan nan nan nan ....]
If I try self.X[[True, False, True], AGE_COLUMN]
for example it returns the indexed rows. But with the isnan
array it does not work.
How can I fix this to set the nans to the mean.