[PYTHON MATRIX-SIG] Array comparisons, and determinants

David Ascher da@maigret.cog.brown.edu
Fri, 25 Oct 1996 12:25:35 -0400 (EDT)


> The original poster's request has a utility which I think is being
> missed.  The goal of expecting x >= 0 (or any other operator) to mean
> x[i] >= 0 for every i, is not to get back a truth value, it is to get
> back a boolean mask.  Data parallel languages of many stripes and
> colors have historically allowed constructs like
> 
> <array declaration a, b, c>
> where( a > 0) b = c
> if (a > 0) b = c        (means the same thing)
> a = b > c		(creates a "vector mask")
> x = a * <complex function>	(selects complex function only for
> 				elements where b > c)
> 
> I do not yet know if I can think of a reason why I would want to do
> exactly this in Python, but that is what the request means to me.
> Seen in this light, it is of absolutely no consequence whether x =
> [1,-1], or any other curious arrangement of elements, since the goal
> is not to get back a single boolean for use in a scalar conditional,
> but a vector mask for use in array expressions.

Isn't that what the ufuncs provide?

>>> b
 0.          0.84147098  0.90929743  0.14112001 -0.7568025 
-0.95892427 -0.2794155   0.6569866   0.98935825  0.41211849
-0.54402111 -0.99999021 -0.53657292  0.42016704  0.99060736
 0.65028784 -0.28790332 -0.96139749 -0.75098725  0.14987721
 0.91294525  0.83665564 -0.00885131 -0.8462204  -0.90557836
>>> greater_equal(b, 0)
1 1 1 1 0
0 0 1 1 1
0 0 0 1 1
1 0 0 0 1
1 1 0 0 0

>>> choose(greater_equal(b, 0), (b, -b))
 0.         -0.84147098 -0.90929743 -0.14112001 -0.7568025 
-0.95892427 -0.2794155  -0.6569866  -0.98935825 -0.41211849
-0.54402111 -0.99999021 -0.53657292 -0.42016704 -0.99060736
-0.65028784 -0.28790332 -0.96139749 -0.75098725 -0.14987721
-0.91294525 -0.83665564 -0.00885131 -0.8462204  -0.90557836



=================
MATRIX-SIG  - SIG on Matrix Math for Python

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