Issue
Lets say i have the following case:
array1=np.array([[1,0,0],[0,1,0],[0,0,1]])
array2=np.array([0,0,1])
now
array1[2]
gives me the output
[0,0,1]
so now i want to have code that gives the index of array1
(in this case 2
) as the output for matching array2
to array1
.
Is there any elegant way to do this? i tried numpy.where
but didn't get it right.
Solution
I am not sure I understand your question correctly. But you could either do this:
import numpy as np
np.where((array2 == array1).all(axis=1))
You can do this:
index = np.argmax([0,0,1])
Or use this:
indices = np.where(np.array([0,0,1]) == 1)
Answered By - sehan2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.