我有一个名为“array”的数组,其大小为 (45, 41),其中应包含 (-200, 200) 范围内的值。但是,某些值已通过在其值上添加 10,000 来进行“标记”。我想通过以下方式取消标记这些元素:如果相关元素大于 8000,则减去 10000(如果大于 8000,则必须对其进行标记)。
所以本质上,在伪代码中,我希望:
for i in 1:45
for j in 1:41
if array[i,j] > 8000
array[i,j] = array[i,j] - 10000
任何帮助将不胜感激,非常感谢!
编辑:这是我的完整代码:
#Read file
cubes=iris.load(pathfile)
print cubes
wind=cubes[0]
print wind
#Select the month
wind_cut = wind[11, :, :, 0]
array=wind_cut.data
print array.shape
for i in 1:45
for j in 1:41
if array[i,j] > 8000
array[i,j] = array[i,j] - 10000
我得到的只是一个缩进错误。我是 python 和这个网站的新手,很抱歉我是个菜鸟。
最佳答案
如果您正在使用 numpy 数组,请尝试以下操作:
array[array>8000] -= 10000
关于python - 仅从数组中的大元素中减去 10000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26673224/