What is the most efficient way to use a mask to select elements of a multidimensional numpy array, when the mask is to be applied with an offset? For example:
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
A similar question is posted here: Setting values of Numpy array when indexing an indexed array but I'm using a mask and I'm not asking why it doesn't work.