Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
finding point in m grid
#1
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])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  connecting the first point to the last point Matplotlib omar_mohsen 0 4,579 Jan-15-2020, 01:23 PM
Last Post: omar_mohsen
  finding the closest floating point number in a list Skaperen 17 8,238 Sep-19-2019, 10:39 PM
Last Post: Skaperen
  finding the next higher representable floating point value Skaperen 0 1,935 Sep-13-2019, 11:16 PM
Last Post: Skaperen
  Finding nearest point of a Multidigraph in Python 3.7 stixmagiggins 5 3,740 Aug-24-2019, 08:51 AM
Last Post: ThomasL
  [Geometry] Finding centers of each grid in pointgrid andre 2 3,038 Aug-22-2017, 12:09 PM
Last Post: andre

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020