linear algebra in pure Python?
Douglas du Boulay
ddb at crystal.uwa.edu.au
Wed Jul 26 22:23:23 EDT 2000
Tim Hochberg wrote:
>
> Douglas du Boulay <ddb at crystal.uwa.edu.au> writes:
>
> > I know that there is the Numeric python extension and/or the
> > Matrix extension MatPy, but is there not anywhere a pure Python
> > linear algebra package exploiting lists of lists for matrices and the
> > like?
> > (I would like to use eigen analysis etc. with JPython)
>
> Conrad has already pointed you to his fully Python array
I am actually looking for the extra bits to solve systems of equations
and
the like.
> package. Another option would be to use JNumeric which is a (more or
> less) drop in replacement for Numeric for use with JPython. The
> LinearAlgebra package has not, unfortunately, been ported(1), but if
Thanks, Yes I have already looked at JNumeric. I actually spent a week
or so
modifying the PyMultiarray to accept Measurement (value,variance) pairs
and propogate them through multiplication addition etc, only to find out
that the matrix vector arithmetic I was doing (predominantly 3x3 or 4x4)
took from 10 to 30 times longer than the original pure-python based
matrix class (exploiting lists of lists) which I was using.
Needless to say I was disapointed. I am sure it would be terrific
as the matrices get larger, but I don't need that at the moment.
I suspect the big killer was the very repetitious type coercions
involved,
which require construction of many temporary matrices
(and which I don't have any control over).
On the topic of JNumeric, are you interested in a wedge/cross product
and Levi-Cevita antisymmetric tensor function add on for PyMultiarray,
or would that blow the equivalence with Numeric?
> you are only interested in operating on real matrices, there are
> several Java packages out there that will perform various linear
> algebra operations(2). Interfacing between JNumeric and these outside
> package is relatively easy(3).
That sounds like the way to go! I'll check it out.
> (2) Colt (http://tilde-hoschek.home.cern.ch/~hoschek/colt/index.htm)
> is the one I've looked at most recently. You might also want to look
> at Nist's JavaNumerics page (http://math.nist.gov/javanumerics/).
>
> (3) Function to convert between JNumeric and Colt type matrics are as
> simple as:
>
> from Numeric import *
> from cern.colt.matrix import *
> from cern.colt.matrix.impl import *
>
> def JNToColt(ja):
> nAxes = len(ja.shape)
> if nAxes not in (1,2,3):
> raise ValueError, "Colt only supports 1, 2 and 3 dimensional arrays"
> constructor = [DenseDoubleMatrix1D, DenseDoubleMatrix2D,
> DenseDoubleMatrix3D][nAxes-1]
> return constructor(ja)
>
> def ColtToJn(ca):
> return array(ca.toArray())
That seems easy enough.
Thanks for your help
Doug
More information about the Python-list
mailing list