lundi 18 février 2019

How to randomly sample 1 data point from each grid's cell

I would like to know how to create an X number of random points in each grid cell. If I have the data below and a grid, how do I sample 1 random data point within each cell?

x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
y = x*2

[x,y] = np.meshgrid(x,y)
x = np.concatenate(x)
y = np.concatenate(y)

xy = zip(x,y)

Xg = np.linspace(0,20,6)
Yg = np.linspace(0,40,6)
[Xg,Yg] = np.meshgrid(Xg,Yg)
Xg = np.concatenate(Xg)
Yg = np.concatenate(Yg)

I tried just using random.sample(xy,36) but its not sampling a random point within each grid cell. Also, is it possible to randomly sample a point in each grid, but instead the center grid cells would randomly sample two points in those cells?




Aucun commentaire:

Enregistrer un commentaire