I am creating a numpy binary array with zeros and ones as follows:
import numpy as np
x = np.zeros((10, 10, 10))
x[:4, :4, :4] = 1
x = x.ravel()
np.random.shuffle(x)
x.reshape(10, 10, 10)
Now what I want to do is randomly sample 20 positions within this array where the value is 1. i.e. I want to randomly sample twenty 3D coordinates where the volume elements are turned on.
I am guessing the way to do this would be to get a position mask of all the positions with the positive value and then sample from that but I cannot figure out how to generate that mask with numpy!