Issue
I have an array c
, another array d
. how can I check if d[1]
ord[3]
ord[5]
ord[7]
is in array c
?
c = np.array([[ 1, 1,0],
[ 1,-1,0],
[-1, 1,0],
[-1,-1,0]])
d = np.array([[2,2,2],
[1,1,0],
[2,8,8],
[6,8,8],
[2,2,2],
[4,9,0],
[2,2,2],
[3,2,2]])
I tried g = np.any(c == d[1,3,5,7])
,but it doesn't work. In this case, the result should be True
because [1,1,0] is in array c
. Can anyone help me?
Solution
Try this
# to check if a row in its entirety match a list,
# use all on axis=1 first, then check if any rows match using any
(c==[2,1,0]).all(1).any()
False
For multiple checks
# use bit-wise | (instead of or)
((c==[2,1,0]) | (c==[3,1,0]) | (c==[5,5,0])).all(1).any()
Answered By - not a robot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.