[PYTHON MATRIX-SIG] Matrix multiplies and syntactic nits

Hinsen Konrad hinsenk@ere.umontreal.ca
Mon, 13 Nov 1995 15:51:13 -0500


   defines functions and a number of useful constants.  Should I rename this  
   module to Mx.py, or something similar so that people will be more inclined  
   to use "import Mx" rather than "from Matrix import *" (which is what I use  

I don't see any need to do this. Anyone can always define a shorter
name by writing
  import Matrix
  Mx = Matrix
So I'd keep the "official" name understandable.

   2) I have two possible ways to implement matrix multiplies:

   a) a % b

NOOOOOOOOOO!

   enough of a resemblence to X to be reasonably mnemonic.  However, this  
   breaks the current conceptual elegance of the system where every operator  
   works on matrices (more or less) exactly the way it works on python scalars.

It's not just a matter of conceptual elegance, but of being able to
write code that works identically with matrices and scalars. And of
easily understanding what a certain piece of code does.

   b) a.matrixMultiply(b)

   This is the obvious solution, however it does make matrix equations  
   extremely ugly to type.  Possibly an abbreviation is called for in this  
   particular case?

Probably yes. But I'd still keep the long name for those who want to
write clear code.

   The following are 2x3 matrices of integers.

   a) Matrix_i((1,2,3),(4,5,6))

   b) matrix([[1,2,3],[4,5,6]], 'i')

   Opinions on which you should get with str(M)?

I'd prefer the first. In fact, I'd prefer a name like "IntMatrix"
instead of "Matrix_i". It is not at all obvious that the attached
letter indicates the type.

I don't like the second notation at all; it somehow implies that 'i'
is a string argument that could have any value. If you want a notation
that indicates the type as an argument, why not use types.IntType
instead of 'i'?

-------------------------------------------------------------------------------
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
=================