Aaron Watters arw@dante.mh.lucent.com
Tue, 17 Jun 1997 09:44:49 -0400

Thanks for the response

> How do you want to compare your arrays? If you just want to compare them
> like tuples you could use:
> > >>> cmp(tuple(xx[0]),tuple(xx[1]))
> If you want to compare the sums of the elements, you could use:

The only problem with this is that the internal representation
for a tuple of floats must be 12x larger than for a numeric array,
not to mention the speed penalty for all those mallocs.
Of course, for now, this is exactly what I will do.

I suppose for my immediate purpose I'd like to compare arrays
any way so that I could use the list.sort builtin on a list of arrays
and get all equal arrays grouped together.  This would require
that if cmp(a1, a2) is negative then cmp(a2, a1) is positive nonzero
and if cmp(a2, a3) is also negative then cmp(a1, a3) is negative,
and a1==a4 iff cmp(a1,a4)==0.

These are the "axioms of cmp" that are assumed by list.sort
and other Python facilities.

Is there any problem with lexicographic ordering?  I understand
that cmp() may have no reasonable interpretation from a
numeric perspective per se, but you'd still like to be able to do
"row sorts".

>From a database perspective I'd like to implement the
analogue of SQL "group by", ie, as in

select a,b, avg(d+e)
from array1
group by a,b

The "natural" way to do this would be to
align the rows of array1 in a list of [a,b,d,e]
and then sort the list lexicographically to
group equal a,b pairs together.  At least *I*
think it would be natural.  -- Aaron Watters

ps: alternatively if there were some way
  to get partitions of indices where a and b
  were equal this might do just as well in
  this instance.  I can't figure out how to do
  this efficiently for all pairings of a,b at once
  (maybe my ignorance).

MATRIX-SIG  - SIG on Matrix Math for Python

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