当使用掩码以偏移量应用时,选择多维numpy数组元素的最有效方法是什么?例如:
import numpy as np
# in real application, following line would read an image
figure = np.random.uniform(size=(4, 4)) # used as a mask
canvas = np.zeros((10, 10))
# The following doesn't do anything, because a copy is modified
canvas[np.ix_(np.arange(4) + 3, range(4))][figure > 0.5] = 1.0
print np.mean(figure > 0.5) # should be ~ 0.5
print canvas.max() # prints 0.0
这里有一个类似的问题: 在索引数组时设置Numpy数组的值, 但我正在使用掩码,而且我不是在问为什么它不起作用。