我遇到了一个有点简单的问题。我有一组数据,我想替换每个值,如果该值大于X.当大于x时,替换数组中的值
为了解决这个问题,我写了一个小脚本例子给出了同样的想法更大:
import numpy as np
# Array creation
array = np.array([0.5, 0.6, 0.9825])
print array
# If value > 0.7 replace by 0.
new_array = array[array > 0.7] == 0
print new_array
我想获得:
>>> [0.5, 0.6, 0] # 0.9825 is replaced by 0 because > 0.7
谢谢你,如果你我能帮助;)
编辑:
我没有找到这个主题可以帮助我:Replace all elements of Python NumPy Array that are greater than some value 由@ColonelBeauvel给出的答案没有在上一篇文章中注意到。
非常感谢!它工作得很好!我也在观看'np.where';) – Deadpool