linear algebra in pure Python?

Tim Hochberg tim.hochberg at ieee.org
Wed Jul 26 11:21:14 EDT 2000


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
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
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).

JNumeric is currently available at http://members.home.net/tim.hochberg/.

-tim

(1) This is because I've been waiting for an appropriate, open source,
package to use as a basis for this. None of the ones I've seen so far
support complex numbers though, so I'm still waiting.

(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:

rom 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())



More information about the Python-list mailing list