doucmentation bug or bug? p or q for numerical arrays

Colin J. Williams cjw at sympatico.ca
Thu Jul 29 17:43:07 CEST 2004


Peter Otten wrote:
> Alan G Isaac wrote:
> 
> 
>>from Numeric import *
>>p = array([1, 1, 0, 0])
>>q = array([1, 0, 1, 0])
>>print logical_or(p,q)    #expected result
>>print (p or q)               #prints p
>>
>>This might be expected, except for the documentation:
>> http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm#pgfId-36127
>>
>>"Universal Functions, or ufunc s. The operators which invoke them when
>>applied to arrays are indicated in parentheses."
>>
>>And then numarray has the same documentation (in the manual)
>>but chokes altogether on the use of 'or'.
>>
>>There is a like problem with 'and'.
>>
>>Am I misreading something?
>>Are there actually operators for these functions?
> 
> 
> Unlike '&', '|' and '~', the logical operators 'and' and 'or' cannot be
> overridden, 'not' not in a useful manner (__nonzero__() must return an
> integer). The documentation is probably wrong.
> 
> Peter
> 
The not yet released version of PyMatrix, which subsclasses NumArray, 
behaves as follows:

import PyMatrix.matrix as _m
p = _m.M([1, 1, 0, 0], type= _m._nt.Bool)
q = _m.M([1, 0, 1, 0], type= _m._nt.Bool)
print p ^ q     # -> [[F T T F]]
print p & q     # -> [[T F F F]]
print p | q     # -> [[T T T F]]

Colin W.




More information about the Python-list mailing list