[PYTHON MATRIX-SIG] Matrix multiplication
Konrad HINSEN
hinsenk@ere.umontreal.ca
Mon, 24 Jun 1996 13:23:40 -0400
> I may have missed any previous discussion on the implementation of
> matrix multiplication in Numerical Python. Anyway, I understand that
> the current implementation of .matrixMultiply() requires arrays to be
> 2-dimensional (has this changed?).
True. As a temporary solution, I can offer a (slow) Python function
that is more general:
def dot(a1, a2):
r1 = len(a1.shape)-1
r2 = len(a2.shape)-1
axes = [r1] + range(r1)
a1 = a1.transpose(axes).copy()
f = a1.reshape
a1 = apply(f, a1.shape + r2*(1,))
a2 = a2.copy()
f = a2.reshape
a2 = apply(f, a2.shape[0:1] + r1*(1,) + a2.shape[1:])
return Numeric.add.reduce(a1*a2)
-------------------------------------------------------------------------------
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
=================