0

For example, if I have the 2D array(df_nump) as follows:

array([[0.78, 0.806, 0.837, 0.831, 0.813, 0.802, 0.792, 0.773, 0.769,
        0.72, 0.676, 0.606, 0.428, nan, nan, nan, nan, nan, nan, nan,
        nan, nan, nan, nan, nan, nan, nan, nan],
       [0.866, 0.911, 0.921, 0.923, 0.906, 0.893, 0.881, 0.86, 0.841,
        0.803, 0.782, 0.702, 0.602, nan, nan, nan, nan, nan, nan, nan,
        nan, nan, nan, nan, nan, nan, nan, nan]])

The desired result is

array([[0.78, 0.806, 0.837, 0.831, 0.813, 0.802, 0.792, 0.773, 0.769,
            0.72, 0.676, 0.606, 0.428],
           [0.866, 0.911, 0.921, 0.923, 0.906, 0.893, 0.881, 0.86, 0.841,
            0.803, 0.782, 0.702, 0.602,]])

How should I transform?

I find using df_nump =[[i for i in row if ~np.isnan(i)] for row in df_nump] But typing the result is a list and i want array type Thanks!

nilou.mhy
  • 23
  • 3
  • 2
    Does this answer your question? [Removing NAN's from numpy 2-D arrays](https://stackoverflow.com/questions/29438329/removing-nans-from-numpy-2-d-arrays) – zamir Jan 15 '20 at 09:43
  • Your solution is pointing to the right direction. Now just use it as numpy-indexing (see zamir's link) – offeltoffel Jan 15 '20 at 09:47

0 Answers0