6 Oct 21:29
multi-comparison expressions
From: John <john <at> saponara.net>
Subject: multi-comparison expressions
Newsgroups: gmane.comp.python.numeric.general
Date: 2008-10-06 19:32:55 GMT
Subject: multi-comparison expressions
Newsgroups: gmane.comp.python.numeric.general
Date: 2008-10-06 19:32:55 GMT
hi,
why does the ValueError appear below, and how can i make that 2<a<5
expression work when a is an array?
thanks.
>>> from numpy import reshape,arange
>>> a=reshape(arange(9),(3,3))
>>> a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> 2<a
array([[False, False, False],
[ True, True, True],
[ True, True, True]], dtype=bool)
>>> a<5
array([[ True, True, True],
[ True, True, False],
[False, False, False]], dtype=bool)
>>> 2<a<5
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()
nor does it work with constant arrays:
>>> from numpy import zeros
(Continue reading)
RSS Feed