Numpy equivalent of if/else list comprehension

前端 未结 1 1536
鱼传尺愫
鱼传尺愫 2020-12-10 16:14

Is there a numpy way of doing

n = [x-t if x > 0 else x for x in nps]

similar to this

n = np.array(a)
n[np.abs(n) < t]         


        
1条回答
  •  一向
    一向 (楼主)
    2020-12-10 16:36

    Can't test now, but try

    np.where(n > 0, n - t, n)
    

    See documentation

    0 讨论(0)
提交回复
热议问题