简体   繁体   English

Numpy等效于if / else列表理解

[英]Numpy equivalent of if/else list comprehension

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] = 0

something like this perhaps? 像这样的东西?

n[n > 0] = n-t

Can't test now, but try 现在无法测试,请尝试

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

See documentation 参阅文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM