MATLAB2Python
Colin J. Williams
cjw at sympatico.ca
Fri Apr 30 08:31:55 EDT 2004
John Hunter wrote:
>>>>>>"Colin" == Colin J Williams <cjw at sympatico.ca> writes:
>>>>>>
>>>>>>
>
> Colin> You might like to take a look at PyMatrix. It is still
> Colin> very much a development project, but I would appreciate
> Colin> your thoughts on the areas where it is deficient, as
> Colin> compared with MatLab.
> Colin> http://www3.sympatico.ca/cjw/PyMatrix
>
>I looked over your site and examples, but didn't see any explanation
>of what PyMatrix provides over the required numarray
>
You are right, the documentation needs improving.
The following is illustrative of matrix usage:
# tRegrn.py To use linear regresssion to illustrate matrix usage
# Note: PyMatrix provides a function to handle this sort of thing
import PyMatrix.matrix as m
# Suppose we have A*x= b, where A (a matrix) and b (a column vector) are
observed and we wish to
# obtain a least squares estimate of x.
# To illustrate we generate a test case:
x= m.M([1, 2, 3], type= m._nt.Float64).T
A= m.random(shape= (10, 3))
error= (m.random(shape= (10, 1)) - 0.5)/10 # ie. -0.05 .. 0.05
b= A * x + error
# solution
xEst= (A.T * A).I * A.T * b
print 'xEstimate:', xEst
>and all the
>helpful linear algebra and summary functions it provides in
>numarray.linear_algebra and numarray.linear_algebra.mlab. With the
>exception of Hilbert, most of the code seems like a wrapper of
>numarray functionality.
>
There are a few other functions and methods, but the documentation makes
it clear that PyMatrix is based on numarray, in fact M (the main matrix
class) is a a sub-class of NumArray.
Why based on numarray, rather than numeric? Because, at the time the
project was started, numarray seemed to be set to replace numeric.
For a full list, see:
http://www3.sympatico.ca/cjw/PyMatrix/Doc/PackageEntry.html
>Is the main difference how you define the default behavior of
>operators?
>
The main differences are:
- PyMatrix is focused on two dimensional numeric structures,
row and column vectors are handled as matrices.
- It permits matrix arithmetic, for compatible matrices A
and B and integer n, the matrix operations A+B, A-B, A*B,
A/B and A**n are recognized.
- It uses properties to provide basic matrix operations such as:
I Inverse
T Transpose
EValues Eigenvalues
SVD Singular Value Decomposition
Det Determinant
- It provides a method to build sub-matrices into a larger
matrix
- It provides methods to aggregate data by row or column
>Or is this just a starting point for a much larger
>package?
>
>
No, quantiles are likely to be added soon and possibly symmetric
matrices, although it is not clear that the potential storage saving
justifies the additional processing. I am certainly not seeking the
bulk of SciPy.
c.l.p has a number of postings similar to "MATLAB2Python" from Sarge,
see below. If something like Huaiyu Zhu's MatPy were available then, it
seems to me, it could be of help to the Python user who works with matrices.
Colin W.
>Thanks,
>JDH
>
>
Hi, everybody!
I'm a moderately experienced programmer in Matlab, and looking for a
free computational language (Matlab is *REALLY* expensive for an
individual, like me).
I came across Python (actually Scipy) and immediately felt
comfortable with the interface and syntax.
I'm still a newbe, so, before attempting a serious work on it, I'd
like to hear any opinion about migration from Matlab to Python, and
also a rough comparison between these two languages.
Thanx in advance, and excuse me for my very bad English (I'm not a
native English speaker),
Sarge
More information about the Python-list
mailing list