Python Numpy mask NaN not working

后端 未结 2 662
庸人自扰
庸人自扰 2021-02-15 12:35

I\'m simply trying to use a masked array to filter out some nanentries.

import numpy as np
# x = [nan, -0.35, nan]
x = np.ma.masked_equal(x, np.nan)         


        
2条回答
  •  后悔当初
    2021-02-15 13:06

    Here is another alternative without using mask:

    import numpy as np
    #x = [nan, -0.35, nan]
    xmask=x[np.logical_not(np.isnan(x))]
    print(xmask)
    

    Result:

    array([-0.35])

提交回复
热议问题