[PYTHON MATRIX-SIG] First experiences

Hinsen Konrad hinsenk@ere.umontreal.ca
Tue, 30 Jan 1996 12:26:11 -0500


   I don't know whether or not sum even belongs in the set of standard
   functions.  On the one hand I'd rather make people use add.reduce
   because it's much more in the spirit of the array object.  On the
   other hand, sum is such a friendly little function.  If it remains in
   the system, then I agree it should get the second argument.

In the spirit of "no needless redundancies", it would be better not to
have this function. Maybe we should add an (optional) module with
standard abbreviations, where we would simply write sum =
add.reduce. That would also be a good way to have clearer standard
names for things like arange() while still having short alternatives
that are available on every system.

   And vice versa.  This is mainly a matter of personal taste, and since
   my taste favors fast_umath, that's going to be the default version for

Its not personal taste, but consistency. I have replaced "fast_umath"
by "umath" in my installation, but then immediately added "from
fast_umath import *" to my only application. I expect to use
mostly the fast version for debugged code, but still I think that
the default should obey the principle of least surprise, and that
is maximum similarity to Python scalar behaviour.

   What you suggest would be very easy to code, but I don't want it
   included in the behavior for reshape.  I like having reshape error
   check my dimensions for me, and I like the fact that reshape doesn't
   copy the whole array, but just returns a new pointer to it.

It could still return a new pointer if the size is the same,
and make a copy only if the size changes. Personally I don't care
about dimension checking; in all my APL code that has never been
a problem. If the size remains the same, then typically the
new dimensions are specified as an expression involving the old
dimensions. I have never had an error there.

   Try this:

   a = array([1,2,3])
   a.concat([4,5], [7,8])
   -> array([1,2,3,4,5,7,8])

   I assume that this is what you're looking for?

Not really. First of all, in most cases I need a non-destructive
version, similar to sequence addition. Second, I really need
it for all dimensions. In my application, I have two 1d arrays
of equal length and have to construct a 2d array from them.
What I used is
   c = array([tuple(a), tuple(b)])
but there ought to be a much cleaner and more efficient way.

BTW, we also ought to have a way to convert arrays to nested
lists and maybe tuples. Oddly enough, Python has no built-in
function list(), although it does have tuple().

   It should probably work along any axis, but I don't have a terribly
   good way to specify the axis and still keep the nice feature of being
   able to concat together an arbitrary number of arrays (very important

One argument could be a tuple of all arrays to be concatenated.

   for efficiency).  It would also be a bit of a hassle to write in C the
   way you're suggesting, would it be enough to add in a standard python
   function with the desired behavior?

That's just a matter of efficiency and has to be tried. In my APL code
this function is used a lot, and often on small arrays.

-------------------------------------------------------------------------------
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. Centre-Ville     | 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
=================