[Numpy-discussion] a==b for numpy arrays
abli at freemail.hu
Mon Dec 11 11:51:29 CST 2006
My unittests got broken because 'a==b' for numpy arrays returns an
array instead of returning True or False:
>>> import numpy
>>> a = numpy.array([1, 2])
>>> b = numpy.array([1, 4])
array([True, False], dtype=bool)
This means, for example:
>>> if a==b:
... print 'equal'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
Now, I think that having a way of getting an element-wise comparison
(i.e. getting an array of bools) is great. _But_ why make that the
result of a '==' comparison? Is there any actual code that does, for
>>> result_array = a==b
or any variant thereof?
Thanks in advance,
More information about the Numpy-discussion