Sum a matrix along a specific axis

The sum function returns the total sum over all elements. Which function could take a second argument to indicate the desired axis?
e.g.
a = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
sum(a, 0) -> [3, 6, 9]
sum(a, 1) -> [6, 6, 6]

Whilst John gives the answer for what you have to currently have to do in IGOR, it would be much nicer to have a single, polymorphic, sum function.

Given a 1D array sum would give a single value.
Given a 2D N*M array sum would give a 1D array (which would be N elements long, if you summed over axis = 1)
Given an n-D array sum would give a (n-1)D array.

It would simplify behaviour. At the moment one has to remember sum, matrixop, imagetransform, etc. I often have to do operations on arrays such as:

[A][B][C][D]

I have to sum over axis=0 and axis=1 to give an array of shape [C][D]. This could be achieved in two steps. At the moment I have to do several rearrangements and it's not pretty

A.
andyfaff wrote:
Whilst John gives the answer for what you have to currently have to do in IGOR, it would be much nicer to have a single, polymorphic, sum function.


Good point. Should be able to get it in for IP7 but probably in the form of an operation not a function.

A.G.
WaveMetrics, Inc.