I’m considering learning Python with the idea of letting go of MatLab, although I really like MatLab. However, I’m concerned that getting all of the moving and independent pieces to fit together may be a challenge and one that may not be worth it in the end. I’ve also thought about getting into Visual Basic or Visual C++. In the end, I keep coming back to the ease of MatLab. Any thoughts or comments regarding the difficulty of getting going in Python? Is it worth it?
-
2Stackoverflow isn't the best place to ask this type of question - it specialises in questions that have objective 'right' answers. For canvassing various viewpoints on a topic, you would probably be better served by a relevant discussion forum. – lvc Apr 14 '14 at 00:27
-
4lvc is right - this is the wrong place. Anyway, your question can't even begin to be answered as you haven't described the sort of programs you want to write (i.e. their necessary functionality, efficiency etc), nor the amount of effort you're prepared to make to learn something new etc.. – Tony Delroy Apr 14 '14 at 00:30
-
1Thanks. I’ve asked this at the python forum. – physics90 Apr 14 '14 at 01:00
-
I would consider taking a look at `Julia`. I'm on the same boat: I want to switch from Matlab to Python because it's free and high level, but I also want a performance improvement. Julia is similar to Matlab's sintax (was inspired by it) and it's performance is comparable to C. Although it's still on a beta stage, it's worth a try. For more information, see http://julialang.org/. – Rafael Monteiro Apr 14 '14 at 01:53
3 Answers
A good place to start is this page: SciPy getting started, which gives an overview of the scientific toolstack that you might be able to use to move towards MatLab from Python: notably the libraries numpy, scipy, matplotlib, and the interactive working environment IPython. In particular, numpy and matplotlib are designed to be very similar to working with MatLab.
NumPy‘s array type augments the Python language with an efficient data structure useful for numerical work, e.g., manipulating matrices. NumPy also provides basic numerical routines, such as tools for finding eigenvectors.
For example in matlab you might write
eye(3)-diag([1 1],1)
and get back
1 -1 0
0 1 -1
0 0 1
In Python/numpy you would write
import numpy as np
np.eye(3)-np.diag([1,1],1)
and get back
array([[ 1., -1., 0.],
[ 0., 1., -1.],
[ 0., 0., 1.]])
With matplotlib
you have full control of line styles, font properties, axes properties, etc, via an object oriented interface or via a set of functions familiar to MATLAB users.
In MatLab for plotting you might write
x=linspace(-pi, pi, 100);
plot(x,sin(x))
In Python/numpy/matplotlib you would write
x=np.linspace(-np.pi, np.pi, 100)
import matplotlib.pyplot as plt
plt.plot(x,np.sin(x))
There is plenty on the web designed for people making the transition, see, e.g. NumPy for Matlab Users.
MATLAB® and NumPy/SciPy have a lot in common. But there are many differences. NumPy and SciPy were created to do numerical and scientific computing in the most natural way with Python, not to be MATLAB® clones. This page is intended to be a place to collect wisdom about the differences, mostly for the purpose of helping proficient MATLAB® users become proficient NumPy and SciPy users. NumPyProConPage is another page for curious people who are thinking of adopting Python with NumPy and SciPy instead of MATLAB® and want to see a list of pros and cons.
You might also like to consider pylab, which brings together numpy and matplotlib into a single namespace, so you don't have to bother with the np
and plt
prefixes I used above. See, e.g., wikipedia.
There are tags on this site that are worth looking at: e.g. numpy, scipy, matplotlib. There is also a question on Python at stats.se which you might find relevant. If you are interested in statistics, or in reading, writing and manipulating tabular data, you will be interested in pandas, Python's answer to R's data frame.
As to C++, it's a great language, but not in the same category as Python. This is not the right place to discuss their pros and cons, but in short, C++ is much closer to the machine than Python and if you spend the time you can write highly optimized code. In Python you can get code working very quickly, glueing together independent pieces and easily reading and writing data from wherever you want to, but Python code can sometimes run slowly (it's like Matlab -- if you vectorize in numpy it's fast, otherwise it's interpreted and slow). You might occasionally want to speed up slow Python code using the ability for Python to call functions defined in C, see, e.g., this question. (I'll leave Visual Basic to one side as it doesn't seem relevant.)
Finally, as noted in the comments, answering any specifics would involve knowing exactly what your requirements were, not just what you want to do, but who you want to do it with, and how much time and money you have available to invest.

- 21,988
- 13
- 81
- 109

- 7,129
- 5
- 34
- 60
Yes Python is worth learning. It was my first major language which I learned over ten years ago. It's used heavily in Linux systems especially when the systems boot up. Also the libraries for the language are very well developed. If you want to design a game PyGame has been around a long time and makes the process pretty easy. If you want to program for networking Twisted is an excellent library they have. And their web framework Django is a beauty.
I found Python to be a very English like language to get into.
If you'd like to you might take a peak at Ruby as well. Ruby allows a lot of different styles of programming. So you can program just like you did in other languages in Ruby (I strictly mean in style). Also Ruby has the most "free" resources for learning and getting into the language online that I've ever seen.
I love both languages. But my answer to you is "Yes!" Python is a great first language.
It all depends on what you want to do, and what method's you prefer.
You can find many mathematical plotting libraries here: https://wiki.python.org/moin/NumericAndScientific/Plotting
Many of which could be an excellent alternative to Matlab.

- 2,365
- 1
- 33
- 46
-
That's all true, but the OP is particularly interested in Python as a Matlab substitute. What's your take on whether Python might be a suitable replacement for Matlab? – TooTone Apr 14 '14 at 00:43
-
This link has a full list of resources for numeric graphing https://wiki.python.org/moin/NumericAndScientific/Plotting . Mayavi is a beautiful 3D renderer. I think some of these tools may very well be an easy transition from Matlab. Matplotlib might be the library he's looking for. – 6ft Dan Apr 14 '14 at 00:47
-
I have really liked (loved) using MatLab over the last 5-7 years or so. The two things that come to mind are the ease of using matrices and and graphing. The software I am writing uses a lot of both. – physics90 Apr 14 '14 at 01:06
-
http://wiki.scipy.org/NumPy_for_Matlab_Users This may cover a lot of the info you're interested in. – 6ft Dan Apr 14 '14 at 01:17
Python is great for Firmware programming like with Arduino's. C++ is great and very powerful for Programming software & applications. If you want to program hardware, go with python. If you want to program software, go with C++. Im learning C++ and its great.

- 1
- 4
-
1to explain my downvote: this doesn't answer the question (Matlab not mentioned), and the comparison of C++ and Python is very skewed towards one particular corner of applications. Moreover all the comments are saying the question is off-topic. (Please note, you are able to delete your own answers. I did so more than once as a new user!:) – TooTone Apr 14 '14 at 00:33
-
3as you say in your profile that you're a child, I can see why you might have thought that Python is useful for electronics programming -- based on what you've done at school. In fact, most software professionals would say that C++ is quite a low-level language suitable for programming hardware, whereas Python is more of a high-level language, and with that, a very good first language to learn. Good luck with it anyway! – TooTone Apr 14 '14 at 00:39
-
Thanks, but I do it at home not school. I'm pretty close to finishing my C++ course! But c++ is a pretty good language. Thanks. @TooTone – SnowMatt Apr 14 '14 at 01:07