[PYTHON MATRIX-SIG] Vector-style operations vs. matrix operations

Hinsen Konrad hinsenk@ere.umontreal.ca
Wed, 13 Sep 1995 14:23:29 -0400

   Chric Chase suggests:
       Generalized inner and outer products (taking user specified binary
       operators) would also be very helpful.

   I'm curious to better understand this proposal.  If it means defining an  
   outer product that can take python binary functions as it's arguments, I  
   would argue that it would be incredibly inefficient (compared to native C),  
   and therefore might as well be implemented in python as a set of "helper"  

   If it means specifying only primitive binary arithmetic operations (like  
   "+" and "*") then I think that it could be implemented efficiently, but I  
   would really like to see some examples of where this would be useful (other  
   than matrix multiplication which will probably be done with special purpose  
   code for efficiency reasons anyway).

Of course general inner and outer products, as well as reduction,
should work with any binary operation, including user-defined
functions. And I agree that this is best done in Python. However, the
most important applications use only the built-in operations
(arithmetic, comparison, logical), so it would make sense to provide a
more efficient solution for them.

There are lots of applications for these things, as any APLer will
confirm. Unfortunately I can't include any APL idioms here due to
character set restrictions :-( But let me give a simple example:
suppose you have an array of data values x (one-dimensional). You
want to make a cumulative histogram, i.e. an array of integers
n in which each entry n[i] indicates the number of values in x
that are larger than b[i], where b[i] is the value of each "bin"
in the histogram. This is just an outer product using >, followed
by a reduction with +:

n = reduce(lambda a,b: a+b, 1, outer_product(lambda a,b: a>b, x, b))

in Pseudo-Python, where the second argument of "reduce" indicates
the rank of the cells to be reduced.

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