Python Forum
finding point in m grid - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: finding point in m grid (/thread-36309.html)



finding point in m grid - jenya56 - Feb-06-2022

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])