Premium problem107. Impute Missing Values with the Column Mean

Medium Locked

2-D array X may contain np.nan. Replace every NaN with the mean of its own column and return the result:

  • column means ignore NaNs
  • compute all the column means first, so an already-replaced value cannot affect a later column's mean

Input

[[ 1.  2. nan]
 [nan  4.  6.]
 [ 5. nan  9.]]

Output

[[1.  2.  7.5]
 [3.  4.  6. ]
 [5.  3.  9. ]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)