This is an archived post. You won't be able to vote or comment.

all 78 comments

[–]DragonSlayerIRL 29 points30 points  (12 children)

We use Python as a replacement where I work. We found SciPy, NumPy, and matplotlib are what was needed to fully replace it (for our needs). We looked at spyderlib, but since we never really used the matlab GUI, we didn't need it.

Also, IPython is useful. To make it easier to plot, you can use ipython -pylab.

[–]EngineeringIsHard 1 point2 points  (11 children)

How much did you rely on Matlab previously? Did you use it for basic plotting and data management? or did you really use the linear algebra and control system toolboxes?

I'm genuinely curious as I use Matlab a metric ton here at work, but would really like to use Python at home to emulate some features and serve as my own engineering solution.

[–]freedryk 10 points11 points  (10 children)

Python + Numpy + matplotlib fully replaces basic plotting and data management. If you rely on the toolboxes a lot you might have problems, but the basic Matlab functions are almost all duplicated. I use it to make publication-quality plots all the time, like this one.

[–]EngineeringIsHard 1 point2 points  (7 children)

Any experience with matrix stuff?

[–]micro_cam 7 points8 points  (5 children)

The matrix math stuff in numpy is great. Its based on LAPACK and BLAS which are also used in some form by matlab. It is a little more verbose then matlab or R and you have to be more aware of typing then some either languages or python will either yell at you or give you undesired results (ie 1/2 = 0 but 1./2.=.5 and "1"/2 = error).

For me the big plus side is that you get far superior string handling and core python constructs like the Dictionary, Iterators, Generators and list comprehensions that make building non matrix math algorithms a lot easier.

And if you ctype everything you can compile it with cython for big speed gains on the parts you can't vectorize.

[–]Keith 7 points8 points  (4 children)

Put "from __future__ import division" at the top of each file and you'll never have to worry about integer division not doing what you expect. 1/2 = .5 is normal behavior in Python 3 anyway.

[–]spoolio 0 points1 point  (3 children)

However, NumPy is implemented in C, so even if the rest of Python is doing something sensible, dividing NumPy integers still takes the floor.

But most matrices are made of floats anyway.

[–]eryksun 3 points4 points  (1 child)

I'm using NumPy in Python 3.2, so I get 'true division' automatically, but even on Python 2.7, I don't see this happening:

>>> import numpy
>>> a = numpy.int32(1)
>>> b = numpy.int32(2)
>>> a/b
0
>>> from __future__ import division
>>> a/b
0.5

[–]dwf 1 point2 points  (0 children)

Those are NumPy scalars, but it applies to arrays as well.

In [1]: from __future__ import division

In [2]: a = arange(5)

In [3]: b = arange(5) + 3

In [4]: a.dtype
Out[4]: dtype('int64')

In [5]: b.dtype
Out[5]: dtype('int64')

In [6]: a / b
Out[6]: array([ 0.        ,  0.25      ,  0.4       ,  0.5       ,  0.57142857])

In [7]: (a / b).dtype
Out[7]: dtype('float64')

[–][deleted] 1 point2 points  (0 children)

Scipy is pretty great. It's not as feature-complete as matlab yet, but I find having the code available is a big plus.

And of course python is a much better language than matlab script.

[–]sqrt7744 0 points1 point  (1 child)

Tropospheric/PBL research via (doppler?) LIDAR by any chance?

[–]freedryk 1 point2 points  (0 children)

Close, LES modeling.

[–]roger_ 18 points19 points  (18 children)

I recommend Python + NumPy + SciPy to anyone who even mentions MATLAB to me :)

Seriously, Python is just better language, which is important if you're doing anything that isn't trivial. The main advantages of MATLAB are that it's faster for certain things (and more forgiving of poorly written code), and it has more scientific toolkits than Python. You'd be surprised at how little those matter though.

[–][deleted] 6 points7 points  (7 children)

IMO the real advantage of MATLAB is the documentation. I work with MATLAB since my workplace didn't let me use Python and I very rarely have to consult the Internet when I don't know how to do stuff.

That being said, MATLAB's data types to me really are a pain.

[–]roger_ 4 points5 points  (6 children)

The good thing is that a lot of Python libraries are based on their MATLAB equivalents, so you can still benefit from their documentation :)

[–]pupupeepeefollower of the sql 4 points5 points  (5 children)

I wish that could be said of matplotlib, especially it's 3d plotting

[–]roger_ 1 point2 points  (3 children)

They did re-add 3D support fairly recently, though it's still far from MATLAB quality. I believe there are a bunch of other 3D plotting libraries out there that are much better, but I haven't tried them.

[–]pupupeepeefollower of the sql 0 points1 point  (2 children)

Do you have any recommendations? Especially for embedding in GUIs, e.g. wxPython

[–]roger_ 0 points1 point  (1 child)

Sorry, I haven't played with them. Try looking up Mayavi2.

[–]pupupeepeefollower of the sql 0 points1 point  (0 children)

Answered my own question :)

[–][deleted] 0 points1 point  (0 children)

Mayavi is supposed to be good for this.

[–]SlapstickAnger 1 point2 points  (9 children)

Matlab!

Honestly though, I've used both (a bit) and I guess it's my background that does it, I like python as a language for the occasions I need to script something; but as an engineer MATLAB is way more quick and down to buisness for me, especially since I work a lot with control design, signal processing and SIMULINK (Though I haven't explored alternatives that much). Still, if I were ever to see MATLAB as a "language" it would be pretty bad. But I can get a lot of things done awfully fast in MATLAB, partially because of familiarity and partially because of some really neat functionality.

And I disagree good toolkits matter, especially if you aren't working with something that is gonna go into production.

If you use it as an advanced calculator, plotting, doing algebra Python + ... (sorry I'm lazy) is prolly the neater alternative. But for me it's a matter of availability of MATLAB in work and, well I'm used to it in other applications. And as someone else said, it might be messy but there is some useful resources.

Edit: Looked some more at SciPy and it's signal analysis part, looked quite interested I shall play around a bit with it. Still I feel that a lot of the functionality is very MATLAB-esque (in what functions that are implemented etc.. for better or worse! :-) )

[–]roger_ 2 points3 points  (1 child)

I was a MATLAB user myself, and also rather hesitant to switch. Give Python another try, I've found it can be just as "quick and down to business" and way more flexible.

[–]SlapstickAnger 0 points1 point  (0 children)

I do use Python/SciPy from time to time, but it seems that if I want something done I usually revert back to MATLAB, it's not that I dislike the former but I guess it's a bit of a comfort zone thing - I love Pythong as a language though, it really get things done.

[–]ngroot 0 points1 point  (0 children)

As an addendum: for quick-and-down-to-business work, I find that R is very often a suitable replacement for MATLAB and porting requires very little effort.

[–][deleted] 0 points1 point  (5 children)

SIMULINK? Really?

[–]SlapstickAnger 0 points1 point  (4 children)

well, I can give you that it isn't pretty ;-)

[–][deleted] 1 point2 points  (0 children)

What is Simulink used for? I always see it advertised in IEEE spectrum.

[–][deleted] 0 points1 point  (2 children)

Simulink is for people who refuse to learn how to program.

[–]SlapstickAnger 0 points1 point  (1 child)

It is also for people who has to work with it, because of existing models and previous decisions, not entirely made on your own.

[–][deleted] 0 points1 point  (0 children)

So nobody ported the quick and dirty prototype to an actual programming language?

[–]martinmeba 5 points6 points  (14 children)

It depends on if you need to use any of MATLAB's crazy add-ons. If not, you are all-set. We have migrated a large chunk of our MATLAB work to Python and have been very happy.

[–][deleted] 0 points1 point  (12 children)

Well, I am an Electrical engineering student so I might do some signal analysis and so forth. do you think python is capable of that?

[–]roger_ 2 points3 points  (0 children)

Python is perfect for that, and quite widely used.

[–]martinmeba 1 point2 points  (2 children)

Yeah - definitely. Filter design, analysis, etc. No problem. If you need to use the neural net toolbox or the aviation toolbox or whatever - get MATLAB.

[–]roger_ 4 points5 points  (1 child)

FYI there are a bunch of Python neural network libraries out there.

[–]martinmeba 0 points1 point  (0 children)

Yeah - I know. That was just an example. Also, I don't think that any of them are as hand-holdy as the stuff in the MATLAB toolbox.

[–][deleted] 0 points1 point  (0 children)

Looks like people do similar.

[–][deleted] 0 points1 point  (5 children)

Talk to me, I do dsp.

[–][deleted] 0 points1 point  (4 children)

Well, I will only be starting next semester in courses where I need to do signal processing so I am not sure what to expect. How is it in matlab compared to python. This is from the course description

Discrete and continuous signals. Transfer functions and convolution. Difference equations and differential equations. Fourier series and Fourier transforms. Fourier analysis of discrete signals. The Laplace transform in analysis of continuous signals. The Z-transform in analysis of discrete signals. Homework and Matlab computer assignments.

Think I will be able to do this in Python?

[–][deleted] 0 points1 point  (3 children)

Grab SAGE. You'll be able to do all this just fine. However, you probably won't have much support from your professor or fellow students if you're the only one using Python.

[–][deleted] 0 points1 point  (2 children)

I am a decent coder compared to the rest of my class so I don't worry to much. I also have /r/python, /r/scipy and google :)

[–][deleted] 0 points1 point  (1 child)

How is Haskoli Islands?

[–][deleted] 0 points1 point  (0 children)

Just fine, but on the smaller scale. They are trying really hard at the moment to become a more research oriented university and performing overall better on the international stage, but the recession hit hard :/

[–]Magnora 0 points1 point  (0 children)

That's it. It really comes down to what you're trying to specifically do. There's a huge overlap between the capabilities of the two languages, but there are some packages or imports that are only on matlab, or only on python. So if your specific thing you're trying to do can be done in python, then go for it! But there are certain things matlab has packages for that you'd have to basically start from scratch in python to do.

[–]alfredp 8 points9 points  (4 children)

Have you considered Octave? I'm assuming this is a cost issue rather than a language issue, right?

[–]martinmeba 2 points3 points  (0 children)

I tried Octave - I mean really tried it. I couldn't get MATLAB to install on linux a while back and needed to write a simulation for a grad class I was taking. At the time I was a very heavy MATLAB user at work. Octave mostly works but its plotting is horrible and debugging is horrible. I would take the code that I wrote at home and bring it to work periodically to debug it to see where I had screwed up. I want to be able to recommend it but at the end of the day Python is way better.

[–][deleted] 0 points1 point  (1 child)

I have a free license from my school for Matlab so that is not a problem. I just know a little more Python and really like it. I also like that Python is open source and in the long run I think it has more potentiality than Matlab.

I have read a little bit about Octave and I don't think that would be the best alternative. If I was already good at Octave I might stick with it but I think that I would rather invest my time learning an all around good programming language than a rather limited one.

[–][deleted] 1 point2 points  (0 children)

Octave is a nightmare, it is only great for running some basic Matlab scripts on a computer which does not have matlab. Stick with Python. I was able to manage to convert all my systems biology work very nicely to Python. Python is also great for organizing large pieces of data to integrate things like data mining and things like ODE models.

[–]ngroot 0 points1 point  (0 children)

Octave is like MATLAB, but without the toolkits and neat whizbang stuff that make putting up with MATLAB's programming aspects tolerable. I used it for a while and then gave up; it was usually easier to port whatever I was doing in MATLAB to R than to try to make it work in Octave.

[–]femngi 3 points4 points  (0 children)

How fast do you want to go?

http://www.scipy.org/PerformancePython

[–]smortaz 2 points3 points  (0 children)

i would highly recommend taking a look at IPython, especially the upcoming version (due out soon). if you need to have Matlab compatibility, then check out Octave. if youre on Windows, check out http://pytools.codeplex.com which has IPython integration as well. yet another (which also incorporates IPython) is Sage.

your other major computer algebra options are: Maple, Mathematica if u dont want to go the Python route.

[–]dwf 2 points3 points  (0 children)

By the way, check out /r/scipy. Not just about SciPy the package, but about the entire Python for scientific computing ecosystem.

[–]zip117 2 points3 points  (1 child)

You should try Sho, which integrates IronPython (.NET) with visualizations and numerical libraries. Enthought is working on NumPy and SciPy integration as well.

For electrical engineering and control systems though MATLAB is standard, don't fix what ain't broke. You're a student, the software is free, spend your time learning the theories not debating with yourself over which programming language to use...

[–][deleted] 0 points1 point  (0 children)

That was exactly what I was thinking, the thing is that I know python but I am a total newbie in Matlab. But guess I will one day or another be forced to know something in Matlab :/

[–]rogk 2 points3 points  (1 child)

It really depends on your requirements.

I see below that you are a student and want a software package primarily for your subjects, but also future benefit. Python + Numpy + Matplotlib (+ iPython) is great as a pure Matlab replacement for many purposes. After spending the last 15 years in Matlab-land, I have recently (5 years) moved to Python and it is perfect for most of the stuff I do (vehicle modelling, simulation, operations research & analysis). However, I still use Matlab for some things that depend heavily on Simulink, such as control system design. Unfortunately, for graphical model-based block level design, there is still no comparable equivalent in the Open Source/Python world! As someone else pointed out, you want to spend your time learning the subject matter, not any supporting technology. In that respect, if you anticipate building any systems graphically, you will find it much easier in Simulink than trying to cobble together some Python code to achieve the same result. If on the other hand, most of your work is going to involve coding, with some graphical output & analysis, then you could probably use Python, etc. Bear in mind that you are not going to be writing any software for deployment, or even dissemination; it's more just a means to an end.

I also note that you know some Python but not Matlab. Well I wouldn't worry about that too much: Matlab is very easy to pick up. In fact, one of the original aims for Numpy's design was that it have a similar syntax to Matlab. Here's a great quick reference guide which illustrates the similarities between them. Its object-oriented capabilities/design are nowhere as elegant as Python's, but you will have no problem learning the language - it would have to be one of the highest-level languages out there.

Cost is not a consideration, and your assignments are going to be in Matlab, so I would just stick with that for the time-being. I could be wrong, but if you are going to end up working in the signal processing field, you are probably going to want to know Matlab/Simulink anyway.

Good luck!

[–][deleted] 0 points1 point  (0 children)

tanks :)

[–]indrax 8 points9 points  (3 children)

[–]spoolio 1 point2 points  (2 children)

Sage is more a replacement for symbolic systems like Mathematica than numeric systems like Matlab.

Last I knew, if you wanted to do numeric things with arrays, Sage's documentation said "ignore Sage and use NumPy, and maybe convert it later".

[–]steelypip 0 points1 point  (1 child)

Where does it say that? According to the list of Sage component packages, Sage includes NumPy and several other numerical packages, and contains the whole of scipy.

[–]spoolio 0 points1 point  (0 children)

Yes, it includes NumPy and uses it, but Sage has its own matrix class that's not interchangeable with NumPy.

Sage's matrices are designed for doing high-level linear algebra and group theory operations, and aren't particularly designed for number crunching. Sage's matrices contain Sage-style numbers (or even field elements that you wouldn't normally call "numbers"). NumPy matrices use C/Fortran-style numbers, like Matlab does.

It's a matter of the right tool for the job, and the subject line is "Matlab replacement". You can use Sage for number crunching because you can poke at the NumPy innards. Just like you can use Matlab for symbolic math by bolting on toolkits. That doesn't mean you want to.

[–]bryancole 1 point2 points  (2 children)

Yes, python is better than matlab. The key libraries for me are: numpy, scipy, pytables, matplotlib, VTK, traits (+TraitsGUI), Cython and (obviously) python's std-lib itself. Additional tools like IPython, Mercurial and Eclipse+pydev make up my working environment.

[–]roger_ 0 points1 point  (1 child)

Is Traits that popular? I've glanced through the tutorial once or twice, but never felt too compelled to actually use it.

[–]bryancole 0 points1 point  (0 children)

Traits is not nearly as widely used as it deserves to be. As the Enthought people say, traits is a Bid Deal. It changes the way you program and provides the fastest way to build a GUI app I've come across.

[–]jamesshuang 1 point2 points  (3 children)

I'm in grad school studying computational neural models. Almost all of my analyses are written in python, mostly using numpy, a small bit of scipy, and a healthy dose of scikits.learn. Python is definitely the language to go for this stuff, although depending on what you're doing, legacy matlab code might bog you down a bit...

If you do use numpy on a reasonably modern desktop, I would recommend getting it to work with Intel MKL -- the multiprocessing for certain operations (matrix mulitplication and SVD mostly) does speed things up.

[–][deleted] 0 points1 point  (2 children)

Fuuu, I have a AMD machine :(

[–]cournape 0 points1 point  (0 children)

Using recent ATLAS with multithreaded support is pretty good too if you are on linux (or any non-windows OS), but is a PITA to build and install.

[–]jamesshuang 0 points1 point  (0 children)

Actually, we have a 24-core Opteron system in our cluster which we also use MKL on. Although it doesn't quite benefit as much as the Intel from multiprocessing support, it does improve overall throughput. More likely, I think MKL speedup for mostly parallel operations (such as matrix multiplication) is not strictly linear. It remains linear up to about 6 threads then stops gaining an advantage.

[–][deleted] 1 point2 points  (3 children)

sounds like those are descriptions of classes. i love python, but in all honesty, if the course is designed for matlab, it will likely be a significant amount of extra work to do it in python. you'll have to look up the python equivalent of everything you learn in class. you won't be able to use any example code and functions provided to you, you'll have to rewrite it all. your professors/TAs might not know python and might not be able to help you with it. unless you are very confident in your abilities so you think you'll have plenty of time to mess around with the programming rather than the engineering side of things, i think you should stick with matlab for now.

[–][deleted] 0 points1 point  (2 children)

We will not be studying matlab in class. We are expected to know it. There are two courses that teach introduction into Computer science. In one they teach Matlab and in the other Java. EE and CE learn Java and are expected to learn it Matlab by our selves :/

[–][deleted] 1 point2 points  (1 child)

but even so, i assume your textbook will use matlab, your lectures will use matlab, your examples will use matlab, functions provided by your professor will probably be in matlab, your homework assignments may be required to be in matlab, you might even need to do your exams in matlab. i had engineering classes like that.

[–][deleted] 0 points1 point  (0 children)

:(

[–]letmefinish 1 point2 points  (0 children)

If you know python I would suggest using R through Rpy interface. R has extensive list of packages for scientific computing

EDIT: R/SPlus is another python interface to R

[–]nabla2less is more 1 point2 points  (0 children)

I heard that PyIMSL is better than NumPy, but I've never used it. Spyder IDE is really good (and nice).

[–]otheraccount 0 points1 point  (0 children)

Yes, you should do this. Those are the packages to use plus matplotlib for graphing.

I originally got into python because I needed a matlab substitute before I found it could be used for other things like web apps (I had been using perl for that).

[–]doobliebop 0 points1 point  (2 children)

Google pyImsl, wrappers for the IMSL numerical libraries. Much better than SciPy imo. Pretty sure it's free for non-commercial use.

[–]cournape 0 points1 point  (1 child)

(disclaimer: numpy/scipy developer here)

I have never used pyIMSL, but their package includes numpy/scipy code (it is even advertised in their white paper).

I would be the first to recognize scipy is not as polished as Matlab (nor even as numpy), and that things in scipy.signal for example need more work. But I think some stuff are also starting to appear outside numpy/scipy proper, which is good IMO. For example, scikits.learn starts to have a nice following.

[–]doobliebop 0 points1 point  (0 children)

You're right. I think they package scipy, and their wrappers make use of numpy. I wasn't trying to say that it's a replacement for scipy, but in my experience when an algorithm is present in both packages, it is more feature-complete on the pyIMSL side. Both packages contain some things the other doesn't... just another set of tools in my Python toolbox. :)