[Numpy-discussion] add.reduce for character arrays

Faheem Mitha faheem at email.unc.edu
Mon May 10 16:32:00 CDT 2004

On Tue, 20 Apr 2004, Todd Miller wrote:

> On Mon, 2004-04-19 at 23:20, Faheem Mitha wrote:
> >
> > Yes, that works. Thanks.
> >
> > In [13]: numarray.objects.add.reduce(s,dim=1)
> > Out[13]: ObjectArray(['abc', 'def', 'ghi'])
> >
> > BTW, that makes me wonder what the rules are for the order in which this
> > reduction proceeds for arrays bigger than dimension two. Since there is no
> > total order in this case, the answer is not obvious.
> (I think) the answer is that for numarray, reductions ultimately occur
> along the innermost axis.  Off-axis reductions are performed by a
> swapaxis between the off-axis and the innermost axis, followed by the
> reduction, followed by a swapaxis back between the new innermost axis
> and the off-axis.  I'm not sure there's an especially good reason for
> the swap back (since the original swapped axis no longer exists),  but
> it seems to be what Numeric does and not doing it in numarray broke
> extension (linear_algebra?) self-tests.
> > For string
> > concatentation (since it is not commutative) at least this matters. I
> > didn't see this documented in the manual but I may have missed it.
> Reductions always occur in order of increasing indexes with the
> "reduction-so-far" as the left operand and the next index as the right
> operand.  Reductions occur in a sort of depth-first manner with the
> outermost dimensions varying most slowly.

Sorry about the slow reply. This message got lost in the mess in my inbox,
which I have recently being cleaning out.

I just wanted to say that it would be useful to have the above documented
in some appropriate place in the numarray manual. 99% of the time the
exact procedure for a reduction won't matter, but when someone is using a
non-commutative operator it will. If this is documented in the manual I
could not find it.



More information about the Numpy-discussion mailing list