这是我的数组:
import numpy as np
a = np.array([0, 5.0, 0, 5.0, 5.0])
是否有可能以某种方式使用 numpy.where
将值 x
添加到 a
中小于我
?
所以像这样:
a = a[np.where(a < 5).add(2.5)]
应该返回:
array([2.5, 5.0, 2.5, 5.0, 5.0])
最佳答案
a = np.array([0., 5., 0., 5., 5.])
a[np.where(a < 5)] += 2.5
如果你真的想使用where
或者只是
a[a < 5] += 2.5
我通常将其用于此类操作。
关于python - 使用 Python numpy where 条件将整体更改为低于特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41463049/