[PYTHON MATRIX-SIG] logical_or and logical_and and # of arguments

Jim Hugunin hugunin@mit.edu
Wed, 19 Mar 1997 15:33:05 -0500


David Ascher writes:
...
> Either logical_or can deal with a large number of arguments or it can't 
--
> if it can't, what does the 3-argument version mean?

logical_or is a binary function (it takes two arguments).  As with all 
umath functions, it will take an optional extra argument to specify a 
preexisting array to hold the result of the computation.

All of the umath "functions" (actually they're objects) have a reduce 
method as well.  This method provides an easy way to get the behavior 
you're looking for, ie.

logical_or.reduce( [x1,x2,x3,...,xn] )

will give you what you want.  In fact, this is useful often enough that 
there's a function for it called "sometrue" which is exactly equal to 
logical_or.reduce.

Note: x1, ..., xn must have the same shapes for this to work.  If this is 
not true, then you'll need to use a combination of binary logical_or's.

-Jim


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________