I have a 2d array of coordinates and I want to find the index of the entry that matches a given coordinate.
For example, my array could be A:
A = [[[1.5, 2.0], [1.0, 2.3], [5.4, 2.3]],
[[3.2, 4.4], [2.0, 3.1], [0.0, 2.3]],
[[1.0, 2.0], [2.3, 3.4], [4.0, 1.1]]]
and the coordinate I want to match is x = [1.0, 2.0]. I want to get the index of the coordinate [1.0, 2.0], which would be (2, 0).
Currently I am doing it as follows:
matching_inds = [(i, j) for i in xrange(len(A)) for j in xrange(len(A[0])) if A[i,j][0] == x[0] and A[i,j][1] == x[1]]
This works, but I feel like there should be something more efficient (the arrays I'm working with are much larger).
I tried np.where() but that doesn't seem to work too well with higher dimensions. It would return indices for all coordinates where the x-coordinate matched, not the x- and y-coordinates.
Any tips would be appreciated.