Given a 2D numpy array containing a number of points:
import numpy as np
points = np.array([
[0, 2],
[1, 3],
[2, 3],
[2, 5],
[3, 4],
[3, 5],
[3, 7],
[4, 7],
[4, 8],
[5, 6],
[5, 9],
[6, 7],
[6, 9],
[7, 8],
[7, 9],
])
What is most performant way to check if a given point (e.g. [6,8]
) is in the array?
For example:
y = []
for i in points:
y.append(np.array_equal([6, 8], i))
True in y
yields False
, as expected.
np.isin([6,8], points)
is unacceptable, as it checks the columns independently, yielding array([ True, True])
.