Despite numpy & scipy's many rounding functions, I cannot find one that allows me to discretize randomized floats with respect to nodes in a 2D mesh grid. For example,
# create mesh grid
n = 11
l = 8
x = np.linspace(0., l, n)
y = np.linspace(0., l, n)
xx, yy = np.meshgrid(x, y, sparse=True)
>>> xx
array([[ 0. , 0.8, 1.6, 2.4, 3.2, 4. , 4.8, 5.6, 6.4, 7.2, 8. ]])
>>> yy
array([[ 0. ],
[ 0.8],
[ 1.6],
[ 2.4],
[ 3.2],
[ 4. ],
[ 4.8],
[ 5.6],
[ 6.4],
[ 7.2],
[ 8. ]])
If I have m
number of random float a=np.random.random((m,2))*l
, how can I round them to the nearest mesh nodes?
Aucun commentaire:
Enregistrer un commentaire