[Tutor] np array.any() question

Bala subramanian bala.biophysics at gmail.com
Fri Sep 21 17:07:36 CEST 2012


Friends,
May i know why do get a Valuerror if i check any value in a is between
3.0 to 5.0 ?
>>> import numpy as np
>>> a=np.array([ 2.5,  2.6,  3.0 ,  3.5,  4.0 ,  5.0 ])
>>> (a > 7).any()
False
>>> (a > 4).any()
True
>>> (3 < a < 5).any()
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()

Thanks,
Bala


More information about the Tutor mailing list