[Numpy-discussion] (a and b) != (b and a) ?
Reggie Dugard
reggie at merfinllc.com
Wed Jun 12 11:56:05 EDT 2002
This is not, in fact, a bug although I've fallen prey to the same
mistake myself. I'm assuming what you really wanted was to use
logical_and:
Python 2.2.1 (#1, Apr 29 2002, 15:21:53)
[GCC 3.0.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Numeric import *
>>> a = array((1,1), 'b')
>>> b = array((1,0), 'b')
>>> logical_and(a,b)
array([1, 0],'b')
>>> logical_and(b,a)
array([1, 0],'b')
>>>
>From the python documentation:
"The expression x and y first evaluates x; if x is false, its value is
returned; otherwise, y is evaluated and the resulting value is
returned."
So the "and" is just returning its second argument, since both arguments
are considered "True" (containing at least 1 "True" element).
On Tue, 2002-06-11 at 23:27, Geza Groma wrote:
> Using Numeric-21.0.win32-py2.2 I found this:
>
> Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from Numeric import *
> >>> a = array((1, 1), 'b')
> >>> b = array((1, 0), 'b')
> >>> a and b
> array([1, 0],'b')
> >>> b and a
> array([1, 1],'b')
> >>>
>
> It looks like a bug, or at least very weird. a&b and b&a work correctly.
>
> --
> Géza Groma
> Institute of Biophysics,
> Biological Research Center of Hungarian Academy of Sciences
> Temesvári krt.62.
> 6726 Szeged
> Hungary
> phone: +36 62 432 232
> fax: +36 62 433 133
>
>
>
> _______________________________________________________________
>
> Sponsored by:
> ThinkGeek at http://www.ThinkGeek.com/
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Reggie Dugard
Merfin, LLC
More information about the NumPy-Discussion
mailing list