Given a matrix (numpy array) A and a vector v.
A = np.array([[5,0],[1,-2],[0,2],[-1,3],[1,2]])
v = np.array([0,2])
What is the best way to get the index of the vector v in the matrix A (in this case one should get 2).
If by best you mean fastest, after thorough experimentation user hpaulj pointed out that np.flatnonzero is a much faster alternative to np.argwhere. You can use it this way:
np.flatnonzero((v==A).all(1))[0]
Output:
2
A[A == v][2]?