[MATRIX-SIG] umath.logical_blah vs normal python functions.
David J. C. Beach
beach@verinet.com
Tue, 18 Nov 1997 12:08:11 -0700
Anthony Baxter wrote:
> is there any reason for this difference in behaviour? It's unexpected (well, it
> was unexpected by me :)
>
> >>> umath.logical_and(4,5)
> 1
> >>> 4 and 5
> 5
>>> 4 and 5
5
4 is true, so return the value of the second operand, which is 5. But that's okay
because 5 is a true value. Since and here is a language construct, you can say
nifty things like
>>> go_to_your_room() and clean_up_the_mess()
and still get the return value from the second (assuming go_to_your_room() was
true)
>>> umath.logical_and(4, 5)
1
4 and 5 are both true, so logical_and returns a 1, which is true.
and, if you want a bitwise and,
>>> umath.boolean_and(4, 5)
4
the bitwise and of the binary representations for 4 and 5.
Dave
P.S. I'm not saying that I like the names...
--
David J. C. Beach
Colorado State University
mailto:beach@verinet.com
http://www.verinet.com/~beach
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________