I have an array of individual ids and a separate array with their corresponding spatial coordinates on a 20x20 plane. I can easily select individuals from specific parts of the plane like so:
from numpy.random import randint
from numpy.random import default_rng
rng = default_rng()
inds = rng.choice(50, size=50, replace=False) #individual tags
locs = np.random.randint(0, 20, size=(50, 2)) #corresponding locations
groups = {
'left' : inds[np.logical_and(locs[:, 0] < 10, locs[:, 1] < 20)],
'right' : inds[np.logical_and(locs[:, 0] > 10, locs[:, 1] > 0)]
}
which gives me a "left" and "right" group. However, I'd like to randomly drop a square of size 4x4 onto the plane and sample only individuals that fall within that square. Any help would be greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire