From: Huaiyu Z. <hua...@ya...> - 2002-03-23 08:31:04
|
On Thu, 21 Mar 2002, Pearu Peterson wrote: > On 20 Mar 2002, Jochen K=FCpper wrote: > > >>>> a > > Aureli> array([0, 1, 0, 0, 1, 0, 1, 0, 0, 1]) > > >>>> b > > Aureli> array([1, 1, 0, 1, 0, 0, 1, 1, 1, 0]) > >=20 > > >>>> Numeric.logical_and(a,b) > > Aureli> array([0, 1, 0, 0, 0, 0, 1, 0, 0, 0]) > >=20 > > This look's correct... > >=20 > > >>>> a and b > > Aureli> array([1, 1, 0, 1, 0, 0, 1, 1, 1, 0]) > >=20 > > ... and this suspiciously like b. >=20 > . and also correct. It is default behaviour of Python `and' > operation. From Python Language Reference: >=20 > The expression `x and y' first evaluates `x'; if `x' is false, its va= lue =20 > is returned; otherwise, `y' is evaluated and the resulting value is > returned.=20 >=20 > So, `and' operation is "object"-operation (unless redefined to somethin= g > else) while logical_and is "elementwise"-operation. There is a section in PEP-225 for elementwise/objectwise operators to=20 extend the meaning of ~ to an "elementizer", so that=20 [1, 0, 1, 0] and [0, 1, 1, 0] =3D> [0, 1, 1, 0] [1, 0, 1, 0] ~and [0, 1, 1, 0] =3D> [0, 0, 1, 0] There are several other places, entirely unrelated to numerical=20 computation, that elementization of an operator makes sense. Huaiyu |