Python vs Matlab [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this questionI'm considering making the switch from MATLAB to Python. The application is quantitative trading and cost is not really an issue. There are a few things I love about MATLAB and am wondering how Python stacks up (could not find any answers in the reviews I've read).
Is there an IDE for Python that is as good as MATLAB's (variable editor, debugger, profiler)? I've read good t开发者_如何学Gohings about Spyder, but does it have a profiler?
When you change a function on the path in MATLAB, it is automatically reloaded. Do you have to manually re-import libraries when you change them, or can this been done automatically? This is a minor thing, but actually greatly improves my productivity.
IDE: No. Python IDEs are nowhere near as good or mature as MATLAB's, though I've heard good things about Wing IDE. Generally, I find IDEs to be total overkill for Python development, and find that I'm more productive with a well-setup text editor (vim in my case) and a separate visual debugger (WinPDB).
Changing functions: Modules must be reloaded after changes using the reload()
built-in function.
import foo
#now you've changed foo.py and want to reload it
foo = reload(foo)
I've switched over myself from MATLAB to Python, because I find that Python deals much better with complexity, i.e., I find it easier to write, debug and maintain complex code in Python. One of the reasons for this is that Python is a general purpose language rather than a specialist matrix-manipulation language. Because of this, entities like strings, non-numerical arrays and (crucially) associative arrays (or maps or dictionaries) are first-class constructs in Python, as are classes.
With regards to capabilities, with NumPy, SciPy and Matplotlib, you pretty much have the whole set of functionality that MATLAB provides out of the box, and quite a lot of stuff that you would have to buy separate toolboxes for.
I've been getting on very well with the Spyder IDE in the Python(x,y) distribution. I'm a long term user of Matlab and have known of the existence of Python for 10 years or so but it's only since I installed Python(x,y) that I've started using Python regularly.
You might also want to check out some of the answers in the following thread, although they don't address your 2 major concerns:
Should i switch to Python?
I'm also a total convert from Matlab:
I have yet to use a full featured Python IDE, but have gotten on pretty well in IPython in combination with Matplotlib, Numpy, Scipy, etc. I actually use the Enthough Python Distribution that comes preloaded with most of the scientific/quantitative packages I need. I've also heard good things about Python(x,y) and Sage
Maybe other IDE's handle this but in IPython I use autoreload which works fairly well.
As others have mentioned, since the numerical/quantitative libraries came to Python instead of a numerical library hacking a language on top, you have an incredible amount of flexibility that you don't have with Matlab. Also the Python community, especially in the numerical/quantitative areas, is really quite fantastic.
I've been in the engineering field for a while now and I've always used MATLAB for high-complexity math calculations. I never really had an major problems with it, but I wasn't super enthusiastic about it either. A few months ago I found out I was going to be a TA for a numerical methods class and that it would be taught using Python, so I would have to learn the language. What I at first thought would be extra work turned out to be an awesome hobby. I can't even begin to describe how bad MATLAB is compared to Python! What used to to take me all day to code in Matlab takes me only a few hours to write in Python. My code looks infinitely more appealing as well. Python's performance and flexibility really surprised me. With Python I can literally do anything I used to do in MATLAB and I can do it a lot better.
If anyone else is thinking about switching, I suggest you do it. It made my life a lot easier. I'll quote "Python Scripting for Computational Science" because they describe the pros of Python over MATLAB better than I do:
- the python programming language is more powerful
- the python environment is completely open and made for integration with external tools,
- a complete toolbox/module with lots of functions and classes can be contained in a single file (in contrast to a bunch of M-files),
- transferring functions as arguments to functions is simpler,
- nested, heterogeneous data structures are simple to construct and use,
- object-oriented programming is more convenient,
- interfacing C, C++, and fortran code is better supported and therefore simpler,
- scalar functions work with array arguments to a larger extent (without modifications of arithmetic operators),
- the source is free and runs on more platforms.
We use the Wing IDE for Python development. It is quite well featured, has integrated debugging support, and can be connected to the profiler of your choice.
Regarding (2), I know exactly what you mean since I miss that very same feature from Lisp, and so far as I know you need to actively reimport the libraries after changing them. This isn't a real hangup, though, since you can easily write (once) a small function that does that for every module you care about, and then put that function on a key macro so all you have to do is eg hit CTRL-T after changing code.
almost everything is covered by others .. i hope you don't need any toolboxes like optimizarion toolbox , neural network etc.. [ I didn't find these for python may be there are some .. i seriously doubt they might be better than Matlab ones..]
if u don't need symbolic manipulation capability and are using windows python(x,y) is the way to go[they don't have much activity on their linux port (older versions are available)] (or need some minor symbolic manipulations use sympy , i think it comes with EPD and python(x,y) supersedes/integrates EPD)
if you need symbolic capabilities sage is the way to go, IMHO sage stands up good with Matlab as well as Mathematica ..
i'm also trying to make a switch ...(need for my engg projs)
i hope it helps ..
after long long tryouts with many editors, i have settled for aptana ide + ipython (including notebook in internet browser) great for editing, getting help easy, try fast new things
aptana is the same as eclipse (because of pydev) but aptana has themes and different little things eclipse lacks
about python a little, don't forget pandas, as it's (i believe) extremely powerful tool for data analysis it will be a beast in the future, my opinion
i'm researching matlab, and i see some neat things there, especially gui interfaces and some other nice things
but python gives you flexibility and ease, anyway, you still have to learn the basics of python, matplotlib, numpy (and eventually pandas)
but from what i see, numpy and matplotlib are similar to matplotlib concepts (probably they were created with matlab in mind, right?)
This question was asked in 2011.
Much more recently, in mid-2013, I've been completely converted to Python, primarily due to the availability of the Matlab-like Spyder IDE, along with all-in-one installers for the entire Scientific Python & IDE environment.
PythonXY (windows only) and Continuum Analytics' Anaconda (Mac/Win/Linux) get you up and running rapidly, with no configuration, in a matlab-like IDE (Spyder), with variable inspector, file explorer, object inspector (displaying live help on the functions you type) etc. etc. It is now a full Matlab replacement for me.
One may switch from MATLAB to Python because Python deals much better with complexity i.e. easier to write, debug and maintain complex code. One of the good reasons for that is, Python is a general purpose language rather than a matrix-manipulation language. Because of this, entities like non-numerical arrays , strings and associative arrays are first-class constructs in Python.
We regularly hear of people and whole research groups that transition from Matlab to Python. The scientific Python ecosystem is maturing fast and Python is an appealing alternative, because it’s free, open source, and becoming ever more powerful. Let's explore of them in details.
Ecosystems of Matlab and Python
Python, by definition, is a programming language. The most common implementation is that in C also known as CPython and is what is mostly referred to as Python. Apart from the programming language and interpreter, Python also consists of an extensive standard library. This library is aimed at programming in general and contains modules for OS specific stuff, threading, networking, databases etc.
Matlab is a commercial numerical computing environment and programming language. The concept of Matlab refers to the whole package, including the IDE. The standard library does not contain as much generic programming functionality, but does include matrix algebra and an extensive library for data processing and plotting. For extra functionality the Mathworks provides toolkits (but these cose you extra).
To do scientific computing in Python, you need additional packages (e.g. Numpy
, Scipy
, Matplotlib
). Additionally, you’ll need an IDE. Many pythoneers come from a Linux environment and use a Python shell and an editor (like vi or Emacs), but people coming from Matlab prefer a feature-rich IDE. Now today there are many handful and powerful IDE available for Python such as PyCharm , Spyder , Jupyter Notebook and many more.
Python packages is being developed by a different (but often overlapping) group of people, who are also users of the packages. Many packages are available for different purposes. In this open source ecosystem most packages are driven by a handful of core developers, but many of a package users contribute to the development by reporting issues, helping with documentation, and making small improvements to the code.
Advantages of Matlab
Let's pick up some of the advantages we can get from Matlab :
- It has a solid amount of functions.
Simulink
is a product for which there is no good alternative yet. - It might be easier for beginners, because the package includes all you need, while in Python you need to install extra packages and an IDE.
- It has a large scientific community; it is used on many universities (although few companies have the money to buy a license).
The problem with Matlab
Here we do not intend to make Matlab look bad. I used to love Matlab myself. However, i think that Matlab has a few fundamental shortcomings. Most of these arise from its commercial nature:
The algorithms are proprietary, which means you can not see the code of most of the algorithms you are using and have to trust that they were implemented correctly.
Matlab is quite expensive, which means that code that is written in Matlab can only be used by people with sufficient funds to buy a license.
Naturally, the Mathworks puts restrictions on code portability, the ability to run your code on someone elses computer. You can run your compiled application using the
Matlab Component Runtime (MCR)
, but your portable app must exactly match the version of the installedMCR
, which can be a nuisance considering that Matlab releases a new version every 6 months.The proprietary nature also makes it difficult for 3th parties to extend the functionality of Matlab.
Furtheremore, there are some other issues that stem from Matlabs origins as a matrix manipulation package:
- The semicolon. It can be useful to show the result when you type code in the console, but in scripts it does not make any sense that one must end a line with a semicolon in order to suppress output.
- Indexing is done with braces rather than brackets, making it difficult to distinguish it from a function call.
Advantages of Python
The Python language has diversified application in the software development companies such as in gaming, web frameworks and applications, language development, prototyping, graphic design applications etc. This provides the language a higher plethora over other programming languages used in the industry. Before picking up some advantage of Python, just give a quick tour here. Now let's see some of the advantages of it -
Extensive Support Libraries
It provides large standard libraries that include the areas like string operations, Internet, web service tools, operating system interfaces and protocols. Most of the highly used programming tasks are already scripted into it that limits the length of the codes to be written in Python.
Integration Feature
Python integrates the Enterprise Application Integration that makes it easy to develop Web services by invoking COM or COBRA components. It has powerful control capabilities as it calls directly through C, C++ or Java via Jython. Python also processes XML and other markup languages as it can run on all modern operating systems through same byte code.
Improved Programmer’s Productivity
The language has extensive support libraries and clean object-oriented designs that increase two to ten fold of programmer’s productivity while using the languages like Java, VB, Perl, C, C++ and C#.
Productivity
With its strong process integration features, unit testing framework and enhanced control capabilities contribute towards the increased speed for most applications and productivity of applications. It is a great option for building scaleble multi-protocol network applications.
Disadvantages of Python
Python has varied advantageous features, and programmers prefer this language to other programming languages because it is easy to learn and code too. However, this language has still not made its place in some computing arenas that includes Enterprise Development Shops. Therefore, this language may not solve some of the enterprise solutions, and limitations include-
Difficulty in Using Other Languages
The Python lovers become so accustomed to its features and its extensive libraries, so they face problem in learning or working on other programming languages. Python experts may see the declaring of cast
values
or variabletypes
, syntactic requirements of adding curly braces or semi colons as an onerous task.Weak in Mobile Computing
Python has made its presence on many desktop and server platforms, but it is seen as a weak language for mobile computing. This is the reason very few mobile applications are built in it like Carbonnelle.
Gets Slow in Speed
Python executes with the help of an interpreter instead of the compiler, which causes it to slow down because compilation and execution help it to work normally. On the other hand, it can be seen that it is fast for many web applications too.
Run-time Errors
The Python language is dynamically typed so it has many design restrictions that are reported by some Python developers. It is even seen that it requires more testing time, and the errors show up when the applications are finally run.
Underdeveloped Database Access Layers
As compared to the popular technologies like JDBC and ODBC, the Python’s database access layer is found to be bit underdeveloped and primitive. However, it cannot be applied in the enterprises that need smooth interaction of complex legacy data
Advantages of Python over Matlab
Python code is more compact and easier to read than Matlab code
Unlike Matlab, which uses end statement to indicate the end of a block, Python determines block size based on indentation.
Python uses square brackets for indexing and parentheses for functions and methods, whereas Matlab uses parentheses for both, making Matlab more difficult to differentiate and understand.
Python’s better readability leads to fewer bugs and faster debugging.
While most programming languages, including Python, use zero-based indexing, Matlab uses one-based indexing making it more confusing for users to translate.
The object-oriented programming (OOP) in Python is simple flexibility while Matlab's OOP scheme is complex and confusing
Python is free and open
While Python is open source programming, much of Matlab is closed
The developers of Python encourage users to input suggestions for the software, while the developers of Matlab offer no such interaction
Python offers a wider set of choices in graphics package and toolsets
With NumPy
, SciPy
and Matplotlib
, you pretty much have the whole set of functionality that MATLAB provides out of the box, and quite a lot of stuff that you'd have to buy for separate toolboxes.
However, MatLab community has their own arguments to choose Matlab or Python, (yes seriously). Good reading though.
Concerning the IDE question, have look at What IDE to use for Python?, where the top answer is PyDev which uses Eclipse.
I also think Sage might be worth looking at
I have recently switched from MATLAB to Python (I am about 2 months into the transition), and am getting on fairly well using Sublime Text 2, using the SublimeRope and SublimeLinter plugins to provide some IDE-like capabilities, as well as pudb to provide some graphical interactive debugging capabilities.
I have not yet explored profilers or variable editors. (I never really used the MATLAB variable editor, anyway).
精彩评论