[Numpy-discussion] Matrix computation in Matlab/Octave style
HZhu at knowledgetrack.com
Mon Jun 5 20:02:43 CDT 2000
Are you craving for Matlab/Octave style expressions in Python? (For example,
A*B is matrix multiplication, not elementwise.) Now you can.
I've just made a package MatPy and started a SourceForge project for it.
It is implemented as wrappers around the Numeric and Gnuplot packages.
You can find the source codes, tests and docs on the home page
The main reason I have written this package is that I'm tired of dealing
with NewAxis and have "Frame not aligned" exceptions. Now matrices and
vectors behave as one would expect from linear algebra.
>>> from MatPy.Matrix import *
>>> A = rand((20,5))
>>> x = rand((5,1))
>>> y = A*x
>>> b = solve(A,y)
>>> print x
>>> print x.T()
[ 0.276 0.553 0.733 0.388 0.5 ]
>>> print x.T()*x
[ 1.32 ]
>>> print x*x.T()
[ 0.0763 0.153 0.203 0.107 0.138
0.153 0.306 0.406 0.214 0.277
0.203 0.406 0.538 0.284 0.367
0.107 0.214 0.284 0.15 0.194
0.138 0.277 0.367 0.194 0.25 ]
>>> z = x + rand(x.shape)*1j
[ 0.276-0.606j 0.553-0.376j 0.733-0.933j 0.388-0.636j 0.5-0.314j ]
[ 3.2+0j ]
There are also matrix and elementwise versions of functions:
expm and exp, sqrtm and sqrt, etc.
Questions, comments, suggestions and helps are all very welcome.
It is a future plan to have an efficient interface to Octave to leverage its
large code base.
Huaiyu <hzhu at users.sourceforge.net>
More information about the Numpy-discussion