[PYTHON MATRIX-SIG] Default axis
Konrad Hinsen
hinsen@physik.rwth-aachen.de
Thu, 15 Aug 1996 10:26:03 +0200
I find myself almost always typing add.reduce(a, -1). What I mean by
this function is to do the reduction along all of the vectors in my
matrix.
Why is it unreasonable to assume that functions like add.reduce act on
the cells of the array?
Anything must be possible; the question is just which
version is most frequent and should be the default. If you follow
the J convention for arrays with subarrays, i.e. the first indices
label the frames and the last the cells, then a sum over a list
of vectors would be add.reduce with axis 0. With axis -1 you would
get a list of the sum of the elements of each vector. Both are
reasonable, but the first one is much more frequent. On the other
hand, there are operations tyhat in such cases would typically
operate on the individual vectors (such as sort), and those would
typically be applied to axis -1.
Of course you can also adopt the opposite convention for index assignment,
but that doesn't change the fact that different functions should have
different default axes.
Now concatenate is another story entirely, and my current thoughts there
are to leave axis=0 as its default. This will be the one exception to
the axis=-1 rule. I also disagree that concatenate should broadcast its
arguments. should concatenate([[1,2,3],[4,5,6]], 0) ->
[[1,2,3],[4,5,6],[0,0,0]]?
I certainly hope not!
I certainly hope that it does! Adding a zero column or row to
an array is a frequent function, and in the old version extremely
complicated (and probably slow). A good example is my interpolation code
(which I don't havew at hand right now, but I think I have posted it a while
ago).
And replying to Carlos' question:
> Since these arrays are aligned in the usual sense (a+b would work),
> one would expect concatenate((a,b)) to work by default. This means
> axis=0. What do others think?
I agree.
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca
Departement de Chimie | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal | Fax: +1-514-343-7586
C.P. 6128, succ. A | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7 | Francais (phase experimentale)
-------------------------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================