Trying to index or remove a numpy array item from a python list, does not fail as expected on first item.
import numpy as np
# works:
lst = [np.array([1,2]), np.array([3,4])]
lst.index(lst[0])
# fails with: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
lst = [np.array([1,2]), np.array([3,4])]
lst.index(lst[1])
I understand why the second fails, I would like to understand why the first one works.
id(lst[0]) == id([lst[0])), if that fails an elementwise check is performed. That fails forlst[0] == lst[1]if those arenumpyarrays.Guarantees that identity implies equalityis what a buggy logic...l = [inf, nan]; i = float("inf"); n = float("nan"); print(l.index(i), 'Works'); print(l.index(nan), 'Works'); print(l.index(n), 'Fails')from numpy import nan, inf