Python Forum

Full Version: finding point in m grid
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have created mgrid and now I want to find index where the point belongs to.
Note, I entertained this solution but obviously need logical and which cannot be added to divmod.
I can go into double for loop but I have to do such search for a rather big grid and my point is not a point but a vector. Any suggestions? Thanks
grid_x, grid_y = np.mgrid[x_min:x_max:50, y_min:y_max:50]
x_new=x[40] #I have vector x
y_new=y[40] #I have vector y
divmod(np.searchsorted(grid_x.ravel(), x_new), grid_x.shape[1])
divmod(np.searchsorted(grid_y.ravel(), y_new), grid_y.shape[1])