views:

423

answers:

2

When I began this project, I thought it would be easy to get libraries for common stuff like matrix math, so I chose to work in Python 3.1- it being the most recent, updated version of the language. Unfortunately, NumPy is only compatible with 2.5 and 2.6 and seems to be the only game in town! Even other stuff that I turned up like gameobjects seemed to be based on NumPy and therefore incompatible with 3.x as well.

Does anyone out there know of a matrix library that is compatible with 3? I need to be able to do the following: matrix add, subtract, multiply, scalar multiply, inverse, transpose, and determinant. I've been looking all day and all roads seem to lead back to NumPy. I even tried this module: http://www.nightmare.com/squirl/python-ext/misc/matrix.py but it too is for 2.x. Even after converting it using the 2to3 tool, I can't get the yarn module that it refers to (and is probably itself 2.x).

Any help is hugely appreciated.

+4  A: 

Given that a large portion of those interested in this sort of development are involved in NumPy, and given their schedule for migrating I think the answer is "no, there is nothing yet".

I would advise treating Python 3.x as "still experimental" and start with Python 2.6 instead. Make some small effort to write your code in a such a way that it won't be too hard to migrate in, say, a year or two, when the Python 3.x series really stabilizes, but don't jump there just yet. Other more general questions have answers that may help you decide.

Peter Hansen
Peter, if you haven't seen it already: the threads with messages http://mail.scipy.org/pipermail/numpy-discussion/2009-December/047058.html and http://mail.scipy.org/pipermail/numpy-discussion/2009-December/047181.html look very promising. Of course, it's still too early to say when `numpy` will be Py3K compatible.
Alok
@Alok, I read them over. They do look quite promising. Other than reducing my "year or two" to "sometime in the next year" though, I don't think it leads me to change my advice. Thanks!
Peter Hansen
@Peter: no of course not, I wasn't suggesting it. But I think it's impressive that numpy managed to at least be `import`able in Py3K in such a small time.
Alok
+1  A: 

EDIT: PyEuclid has supports matrices, vectors up to 4 dimensions and is designed for geometric operations.

Otherwise, the answer is probably not what you want, but:

  • use python 2.x instead, do use numpy (which is really good), until numpy supports python 3.x
  • implement your own Matrix class, since you don't require too much functionality and it's a good exercise to implement. Should be less work than looking a day on the internet.
catchmeifyoutry
These are all the answers I was afraid of. Too late to backport the rest to 2.6. Right now I'm looking into implementing my own. I'll hold out some hope for a miracle, but thanks for the advice, guys.
F. Smith
btw, if you only need to use geometry (this no more than 4 dimensions: Vector4, Matrix4), you might look at pyeuclid: http://code.google.com/p/pyeuclid/source/browse/trunk/euclid.py
catchmeifyoutry
Wow, almost. Actually I will be working with 2x2 matrices, which seems so trivial, but the math still has to hash out right :)
F. Smith
@F.Smith, if "backporting" looks difficult, consider making use of the various "from __future__" options and similar things that have been added to Python 2.6 and 2.7 to simplify the job. See for example http://docs.python.org/dev/whatsnew/2.7.html
Peter Hansen