[PYTHON MATRIX-SIG] First experiences
Hinsen Konrad
hinsenk@ere.umontreal.ca
Tue, 30 Jan 1996 08:39:04 -0500
Yesterday I replaced a rather awkward combination of a shell script
and a Matlab program by a Python program that is shorter, easier to
read, and faster than the old solution. First the most important and
good news: it works, and it produces the same results as the Matlab
code.
Of course I also noticed a few problems/strange features/possible
improvements, and here they are for general discussion:
"mrange" should be called "arange" now. Or maybe something clearer,
e.g. "rangeArray"?
Why add.reduce(...) but outer(add, ...)? I have typed add.outer(...)
more than once, and that makes more sense to me.
There is a function sum() that is almost equivalent to add.reduce() -
almost because it doesn't allow a second argument to specify the
axis. Why?
The more I use it (and see it on my screen), the pseudo-index None
seems strange to me. As a test, I have shown my code to a colleague
who is an active Matlab user. I told him what x[2,3] means and asked
him what he expects x[All, None] to mean. His immediate answer was:
"everything along the first axis, nothing along the second axis." Then
after a pause: "but that doesn't make sense."
So once I again I propose to change the name to "NewAxis" or "New" or
anything else indicating that this index *creates* a new dimension.
A related observation: I have used the combination [All, None] very
often, but no other index expression involving All or None. This is of
course a feature of my application, but I wouldn't be surprised if
appending a new axis were the most frequent use of these
pseudo-indices. In that case it would be worthwhile providing an
equivalent convenience function that is shorter (i.e. less visually
obtrusive).
Currently Numeric.py imports from fast_umath; in my opinion the
default should be umath. Those who want speed can always overwrite the
definition by importing from fast_umath.
A minor cosmetic point: when I print a ufunc, is still says 'ofunc'.
Another cosmetic point: "Array.error" should be "ArrayError".
I don't know how much effort this would be, but I'd really like
reshape() to accept new shapes that lead to a different size. From my
APL/J experience, I found that such reshaping is one of the most
useful methods to construct non-standard matrices. Some examples:
- an NxN array with all elements 37:
reshape(37, (N, N))
- a checkerboard matrix with 0s and 1s:
reshape([1,0],(8,9))[All, 0..7]
We could then eliminate special case constructors like zeros().
Another important function that seems to be missing is appending,
i.e. the equivalent of + for lists. Of course for arrays it has
to work along any axis.
-------------------------------------------------------------------------------
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
=================