[Matrix-SIG] Bug in "reduceat"?

Edward C. Jones edcjones@erols.com
Sun, 02 May 1999 07:02:07 -0400


#! /usr/bin/python

import Numeric

# In NumPy, "reduceat" does not accept an "axis" parameter like
"reduce"
# does. Here are some simple examples for "reduceat". You may
need to change
# "#! /usr/bin/python" to where python is on your machine.

a = Numeric.array([0, 1, 2, 10, 11, 12], 'i')
ind = [0, 3]
b = Numeric.add.reduceat(a, ind)
print b

# The following array might be an image that needs to be reduced
in size or
# a spreadsheet with blocks to be summed.

a = Numeric.array([[ 0,  1,  2, 10, 11, 12], \
                   [ 3,  4,  5, 13, 14, 15], \
                   [ 6,  7,  8, 16, 17, 18], \
                   [20, 21, 22, 30, 31, 32], \
                   [23, 24, 25, 33, 34, 35], \
                   [26, 27, 28, 36, 37, 38]], 'i')
print a
b = Numeric.add.reduceat(a, [0, 3])
print b
tb = Numeric.transpose(b)
print tb
c = Numeric.add.reduceat(tb, [0,3])
print c

# The following fails:
d = Numeric.add.reduceat(a, [0, 3], 1)