convert nan value to zero

前端 未结 9 986
暖寄归人
暖寄归人 2020-11-30 23:28

I have a 2D numpy array. Some of the values in this array are NaN. I want to perform certain operations using this array. For example consider the array:

<
9条回答
  •  离开以前
    2020-12-01 00:35

    You can use lambda function, an example for 1D array:

    import numpy as np
    a = [np.nan, 2, 3]
    map(lambda v:0 if np.isnan(v) == True else v, a)
    

    This will give you the result:

    [0, 2, 3]
    

提交回复
热议问题