a
np.where(np.isnan(a), ma.array(a, mask=np.isnan(a)).mean(axis=1), a)
np.where(np.isnan(a), ma.array(a, mask=np.isnan(a)).mean(axis=1)[:, (np.
    newaxis)], a)
numpy array: replace nan values with average of columns