Python, Matlab and AI question

Alexander Schmolck a.schmolck at gmx.net
Fri Feb 18 15:27:10 EST 2005


Robert Kern <rkern at ucsd.edu> writes:

> dataangel wrote:
>> I'm a student who's considering doing a project for a Machine Learning class
>> on pathing (bots learning to run through a maze). The language primarily
>> used by the class has been Matlab. I would prefer to do the bulk of the
>> project in python because I'm familiar with pygame (for the visuals) but I
>> already have a lot of AI code written in Matlab.
>> I'd like to be able to call Matlab code from within python. I'm not sure
>> this is possible. My code runs in Octave just fine.
>
> There have been some bridges between Matlab and Python, but most of them are
> old, I believe.
>
>    http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html

Actually, I've written a highlevel matlab-python bridge (based on bugfixed and
slightly extended version of the original pymat) which is quite up-to-date; by
and large it makes using matlab from python as easy as if matlab were just
some python library:

>>> from mlabwrap import mlab; mlab.plot([1,2,3],'-o')
<imagine plot here>
>>> mlab.sin([4,5,6])
array([[-0.7568025 ],
       [-0.95892427],
       [-0.2794155 ]])

As you can see from the last example there a certain minor idiosyncrasies
stemming from unbridgable semantic differences between matlab and python
(matlab doesn't have "real" vectors, which means that Numeric vectors are
translated to Nx1 matrices), also the call to matlab of course incurs a
significant overhead compared to Numeric.sin.

All in all I it works quite well for me, though (I've been using it
productively for years now and a couple of other people have also used it) --
so I guess I should finally announce it (there were a few minor things I
wanted to add first, but since people periodically ask for something like it
on c.l.py so now would seem like a good time).

You can find it on sourceforge:

 <http://mlabwrap.sf.net>

I'd appreciate feedback.

'as

p.s. never mind the project activity meter at 0% -- as you can see the latest
version was uploaded mid january this year.



More information about the Python-list mailing list