Issue
I have an array of coordinates as shown below:
import numpy as np
values_to_test = np.array([[1 , 0],[2 , 0],[2 , 0.5],[1 , 0.5],[0 , 0],[2 , 1], [0 , 0.5],[1 , 1],[0 , 1]])
As my ultimate goal, I need to choose the positions from the values_to_test
that contain the specific coordinates of the following array:
specific_values=np.array([[1,0],[0,0],[1,1]])
Hence, I'm expecting a result like: [True,False,False,False,True,False,False,True,False]
I know if this was a 1D
array I could use np.where
but I cannot think about a way to handle this problem.
Appreciate your help
Solution
You could make use of numpy.all
and numpy.any
like so:
>>> (values_to_test[:, None] == specific_values).all(axis=-1).any(axis=-1)
array([ True, False, False, False, True, False, False, True, False])
Answered By - game0ver
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.