I need to find if a numpy array is inside other numpy array, but it seems to work different to python lists.
I tried to search this question in numpy documentation and internet, but not answer.
This is an example:
import numpy as np
m1=np.array([[1,2,3],[5,3,4]])
m2=np.array([5,4,3])
m2 in m1
True
m3=[[1,2,3],[5,3,4]]
m4=[5,4,3]
m4 in m3
False
In numpy I obtain True but with Python lists I obtain False. Is there any numpy function to make this work?
Thanks.
To get the same behavior as
infor lists, you could do something like this:That does the loop over rows in python, which isn’t ideal, but it should work.
To understand what’s going on with the numpy
in, here’s a description of the semantics ofinfrom Robert Kern on the numpy mailing list: