# [PYTHON MATRIX-SIG] Array comparisons, and determinants

**Geoffrey Furnish
**
furnish@laura.llnl.gov

*Fri, 25 Oct 1996 09:14:39 -0700*

Konrad Hinsen writes:
> > Inequalities are often generalised to work for vectors and matrices. For
> > example, x>=0 where x is a vector means x[i]>=0 for every i.
>
> With such a definition, you could have an x for which both x > 0 and
> x <=0 0 are false. But the __cmp__ function has to decide cleanly
> between equal, greater, and less - there is nothing in between.
And Tim Hochberg writes:
> The problem is that __cmp__ can only validly return an integer. Notice
> that for your first example that am array might be neither >=0 nor <0
> ([1,-1] comes to mind), so there's really no valid value to return.
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.
--
Geoffrey Furnish email: furnish@llnl.gov
LLNL X/ICF phone: 510-424-4227 fax: 510-423-6172
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================