# [PYTHON MATRIX-SIG] sum() in 1.0a2

**Konrad Hinsen
**
hinsen@physik.rwth-aachen.de

*Sun, 18 Aug 1996 10:18:05 +0200*

I think sum(a) (and other reductions) should return an array with shape ()
when a is 1d, and not a scalar. Currently, sum(a).anyarraymethod and
sum(a)[0] will fail if a is 1d.
Which is precisely why I have always insisted that array operations
should be implemented as functions and not as methods.
Of course the alternative would be to make rank-0 arrays distinct from
scalars, and this alternative has been discussed a lot in the early
days of the Matrix SIG. But it creates a few fundamental
problems. Everyones idea of arrays is that they are collections of
scalars, and one expects to be able to pick the scalars from an array
by indexing. But if rank-0 arrays are distinct from scalars,
indexing a rank-1 array would return a rank-0 array. Worse, there
would be no obvious way to extract a real scalar from a rank-0
array, so another conversion function would be necessary. The
resulting system would be extremely confusing to users.
Not having specific rank-0 objects is therefore the lesser evil,
but then we have to live with the implementation limitations
given by the Python interpreter.
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
=================