Numerical Python Question

Dr. Des Small des.small at bristol.ac.uk
Tue Dec 4 08:47:06 EST 2001


Yow!

Uwe Schmitt <uwe at rocksport.de> writes:

> Well, i fixed it: I have to use Matrix() in order to construct a
> Matrix whith appropriate __mult__()-method. Now I encountered another
> problem:

[code snipped, x is a n*1 array]
 
>     print "x=", x
>     print
>     print "x'*x=", transpose(x)*x
>     print
>     print "x*x'=", x*transpose(x)
>     print
> 
> This program should output a vektor, then a scalar and finally a matrix.
> But it outputs a vektor and two matrices. 
> I think this is a bug.

This is not a bug; it's documented.  The operator "*" does not perform
matrix multiplication in the linear algebra sense (it does a sort of
element-wise multiplication).  The function you want is
matrixmultiply, as in: 
 
print "x*x'=", matrixmultiply(x,transpose(x))

This is a common source of surprise with people new to Numpy.

Des.
-- 
Dr Des Small, Scientific Programmer,
School of Mathematics, University of Bristol,
Tel: 0117 9287984



More information about the Python-list mailing list