I am a bit puzzled by the python (2.7) list.remove . The deletion documentation says: "Delete the first element from the list whose value is x. This is an error if there is no such element."
So, I think that the value value means that the comparison is based on equality (i.e. == ), not identity (i.e. is ). However, can someone explain the following behavior to me. Both comparisons seem to be used, but rather oddly:
import numpy as np x = np.array([1,2,3]) mylist = [x, 42, 'test', x]
This, of course, will print:
[array([1, 2, 3]), 42, 'test', array([1, 2, 3])]
So far so good. But the following code looks strange:
mylist.remove(x) print mylist
gives
[42, 'test', array([1, 2, 3])]
I would expect it to throw an error, because numpy arrays do not return a boolean operator, but a boolean array. For example, x == x returns array([ True, True, True], dtype=bool) . However, our removal is successful. However, a repetition of the same statement leads to predicted behavior:
mylist.remove(x)
throws out
What's happening?