r/Python • • Aug 05 '19

Python's response to MATLAB

Post image
4.3k Upvotes

372 comments sorted by

View all comments

60

u/Antouziast Aug 05 '19

Young engineer here, PhD student. I have to say Matlab is an awesome tool when it comes to manipulating and exploring data really fast but now I'd love to expand my programming skills and turn towards Python. But on my day to day work it's really hard to branch out since a lot of my tools are written in Matlab.

Also, one of the biggest issues I've encountered with trying to learn Python is how to set up your environment and workflow before even writing a single line of code. I've looked into conda and all but it takes some energy to find the good ressources that will help when you've never used anything else than Matlab which just works out of the box. (Any awesome tutorial to give good practices as to the management of a project in and around the code? i.e. "I'm going to start a project xyz, what's a good practice to manage my code and dependencies in a not cluttery way so that I can start working on the code and not fighting bugs?")

But in the long run I hope to rely more and more on Python than on Matlab!

TL;DR : I'm a Matlab user that wants to avoid the mistakes you do at the beginning when learning Python

6

u/Alexanderdaawesome Aug 05 '19 edited Aug 05 '19

Do you like to play with your environment? Doing write-ups on jupyter is bar none an excellent way to show off your work.
Here is an example of how something you write up may work. It also supports markdowns with Latex syntax, so you can make your findings even more pretty. adding a library is as simple as opening up a terminal and typing

pip3 install **some library**

Debugging:
Lets say you want a file of functions. Call it func.py. Now on func.py you import numpy (for the love of god learn numpy) for any numpy funcs. You write each function with inputs and outputs. Save it. On your main project, say the jjupyter file, you can simply say

from func import *

(there is more syntax to this but it is basically that easy)

Now say you type in a problem and it is giving unexpected results, and you think it may be a problem in one of the functions.

I am not sure how much time you have to learn things, but in this case I really, really recommend Pycharm. You can set up your whole environment on there. (A lot of people recommend anaconda, but for specific environments I have encountered issues). Debugging is as simple as setting a marker and pushing 'run', then stepping through to find the bug. That takes time to learn but it is insanely helpful once you understand how to use it.

Anyway Matlab has better 3d plotting than python, but overall python has a hell of a lot more libraries and open source tools to use. In the long run python will be better for you to know, assuming an engineering company you end up at is not stuck using it.

1

u/I_Feel_It_Too Aug 06 '19

Matlab has better 3d plotting than python

I am curious to know why you say that. I can embed an interactive 3D plot in a web page in Python in the time it takes me to load Matlab. The aliasing and default color scheme of Matlab's make them look like they are from 1994.

1

u/Alexanderdaawesome Aug 06 '19

I rarely use it, so lack of experience?

1

u/I_Feel_It_Too Aug 07 '19

I don't use it that much, either, so I was wondering if I was just missing something obvious.

A counterargument to my pro-python argument is, trying to do something even slightly different from the defaults of the user-friendly Python plotting libs requires magic matplotlib-fu which is a huge pain in the butt. I still feel like I get superior output to any of the alternatives, but it's the plotting equivalent of assembly language. The R people tell me that it's only slightly easier in R, but I haven't done enough R to evaluate that comparison first-hand.