[Numpy-discussion] add.reduce for character arrays
jmiller at stsci.edu
Tue Apr 20 09:54:01 CDT 2004
On Mon, 2004-04-19 at 23:20, Faheem Mitha wrote:
> Yes, that works. Thanks.
> In : numarray.objects.add.reduce(s,dim=1)
> Out: 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.
Todd Miller <jmiller at stsci.edu>
More information about the Numpy-discussion