I have encountered a behavior of the in operator in the context of numpy arrays which i don’t understand.
>>> a=[0,1,2]
>>> x=np.array([a])
>>> b=[3,4,5]
>>> np.append(y,[b],axis=0)
array([[0, 1, 2],
[3, 4, 5]])
>>> a in x
True
>>> b in x
False
My motivation is to build a list of distinct vectors, so i need to be able to use the in operator, and i need a way to extend my list of vectors so that an appended element is also seen as being in the list.
For my list i use a numpy array because the in operator doesn’t work the way i expect.
So my questions here are:
- in the above example, why is b not seen as an element of y?
- how can i append a numpy array to a numpy array of numpy arrays so that the in operator works as expected?
- is there a better way to store vectors (i.e. numpy array of size 3), to that i can add new vectors, and such that the in operator sees newly added vectors as being elements of the structure?