One way to work around this might be to use np.where
with an approximate match:
>>> X = np.linspace(1, 10, 100).reshape((10,10))
>>> np.where(abs(X - 6.3) < 0.1)
(array([5, 5]), array([8, 9]))
>>> X[np.where(abs(X - 6.3) < 0.1)]
array([ 6.27272727, 6.36363636])
Of course, this could give you more than one match, if the epsilon (0.1 in this example) is too large, but the same could be the case when using an exact match, in case there are multiple entries in the array with the same coordinate.
Edit: as pointed out in comments, you could also use np.isclose
, even with Python 2.7 where math.isclose
is not available. Note, however, that np.isclose
will not give an array of coordinates, but an array of True
/False
. If you need the coordinates, you could pipe the result of np.close
through np.where
again.
>>> np.where(np.isclose(X, 6.3636))
(array([5]), array([9]))
>>> X[np.isclose(X, 6.3636)]
array([ 6.36363636])
Alternatively, you could consider changing the function that gave you that coordinate from the LON
array to also return the position of that value in the array. This way, you would not need to use np.where
at all.