29 Apr
2011
29 Apr
'11
1:08 a.m.
Nick Coghlan wrote:
I hadn't really thought about it that way before this discussion - it is the identity checking behaviour of the builtin containers that lets us sensibly handle cases like sets of NumPy arrays.
Except that it doesn't:
from numpy import array a1 = array([1,2]) a2 = array([3,4]) s = set([a1, a2]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'numpy.ndarray'
Lists aren't trouble-free either:
lst = [a1, a2] a2 in lst Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
-- Greg