[Numpy-discussion] precedence of '&' and '>' operators

Tim Leslie tim.leslie at gmail.com
Mon Mar 27 16:46:04 CST 2006


On 3/28/06, Michael Sorich <michael.sorich at gmail.com> wrote:
>
> It seems that the '&' operator has a higher precedence than a comparison
> operator such as '>'. This does not seem so intuitive to me. Is this
> correct?
>

Yep.

http://docs.python.org/ref/summary.html

Cheers,

Timl

eg
> >>>import numpy as N
> >>>N.version.version
> '0.9.6'
> >>>a = N.arange(10)
> >>>a>1 & a<4
> Traceback (most recent call last):
>   File "<input>", line 1, in ?
> ValueError: The truth value of an array with more than one element is
> ambiguous. Use a.any() or a.all()
> >>>(a>1) & (a<4)
> array([False, False, True, True, False, False, False, False, False,
> False], dtype=bool)
>
> Michael
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060327/66393cf5/attachment-0001.html 


More information about the Numpy-discussion mailing list