r/Python • • Aug 05 '19

Python's response to MATLAB

Post image
4.3k Upvotes

372 comments sorted by

View all comments

Show parent comments

54

u/mexiKobe Aug 05 '19 edited Aug 05 '19

The language is ugly

Not at all for numerical calculations / matrix math etc. It’s very good for that, better than Python with numpy. Look at these comparisons https://docs.scipy.org/doc/numpy-1.15.0/user/numpy-for-matlab-users.html

I mean saying it is uglier than C++ is kind of silly. Try doing simple vectorized calculations from MATLAB but in C++ and get back to me on that. And JavaScript? Come on man lol.

But yeah the problem is when engineers and scientists only use it and try to write applications with it. I’ve seen some FUCKED UP code written in MATLAB being used at huge research hospitals and in national security, and “subversioned” with duplicates on Dropbox. It’s actually extremely common, which should be shocking

15

u/[deleted] Aug 05 '19

.mat files, .mat files everywhere, and not a database to be had.

3

u/The_UTMOST_respwect Aug 06 '19

Ya I still like it for plotting stuff up, easy to make pretty plots, compared to my knowledge and proficiency with pyplot, but I'm getting better.

Having used C and C++, and python quite a bit, its still just so easy prototype a bunch of stuff and debug and visualize it in matlab. I'm also a proponent of using it in batch mode whenever possible.

2

u/Feminintendo Aug 06 '19

It takes me about half the time to prototype something in Mathematica as it does in Python, but then the Python version runs roughly an order of magnitude faster, depending of course on the application.

Honestly you're probably faster in Matlab because you think in Matlab, whereas if your brain had been steeped in Python or, like me, Mathematica, then that would be faster instead. It's like a first language.

But I think that's ok as long as we understand the principle of the right tool for the job. I would never use Mathematica in anything for which the phrase "production code" would apply (despite Wolfram's marketing). Rapid prototyping? Sure. The million different one-off scientific computations one does in the course of research? You bet. But there is a whole swath of applications for which it just isn't the right tool. Likewise for Matlab.

7

u/cue_the_strings Aug 05 '19 edited Aug 05 '19

The last paragraph is what I was getting at: it is extremely widespread and incredibly important stuff relies on it.

MATLAB is only good for pure mathematical calculations (especially matrix) and the graphs are half usable.

So, if you're banging up a personal little util to fill some need (calculate something) in your engineering workflow, it might be usable. Also if you're doing a calculation for a paper. Or checking quickly if you're on the right track when solving some problem.

If you need to make a GUI program that does something you use MATLAB for in the background, you have several options.

You could write the GUI code in something decent like Qt (C++) or PyQt (Python) and then redo the math in the same language. You can use Eigen for matrix operations in C++, and of course NumPy in Python.

The second way would be to write the GUI code in Qt or something similar, write the math in MATLAB, generate C code (apparently you can generate C++, too) from MATLAB and compile and link them together.

These options are actual software development and require real programming knowledge.

Of course, there is the third option we all know about: making your GUI house of cards in MATLAB.

I prefer the first option. Numpy's syntax isn't bad enough for me to forgo other benefits Python brings to the table. Actually, I don't mind it at all. So I just write all of it in Python and it's decent software, can be unit tested easily, integrates properly with the OS and other software. Qt and PyQt make it look native, you can easily make parts of the gui drag-and-drop, you can interface with databases easily, issue HTTP requests, interface with devices over serial, etc.

However, you may find Numpy to be a bit slow in some cases. Specifically, sometimes you have to be sure that the calculation you're doing is optimally paralellized to be efficient enough. This is where you'd use C++ and Eigen, and you may as well do the GUI in Qt in C++. There is always an option to create Python bindings for everything if you want to and use Python for GUI.

MATLAB code generation options look okay (never used them, though), but why would you pay for them when there are open source alternatives? MATLAB being closed source means you're at their mercy when you have a problem, you may be in a situation where the offending code is in MATLAB's black box. Or some functionality may be removed or broken in an update. I just don't see the point.

And, at the end, a bit of hyperbole: I'd rather do vector math in JS than GUI or data processing in MATLAB.

0

u/[deleted] Aug 06 '19

[deleted]

3

u/eruesso Aug 06 '19

Well... I call BS on that. If it semi matters, then matlabs paralisation methods are great. But when you really need to optimize, you can't because you are lacking the control over memory.

1

u/I_Feel_It_Too Aug 06 '19

MATLAB is only good for pure mathematical calculations (especially matrix)

It really isn't. For at least a dozen examples....

2

u/Zall-Klos Aug 06 '19

SImpler, Matlab can't find the root of X^2.

1

u/I_Feel_It_Too Aug 07 '19

Isn't there a symbolics toolbox you can get for an extra $6000 that can do high school algebra like that?

4

u/log_2 Aug 06 '19

But yeah the problem is when engineers and scientists only use it and try to write applications with it.

That's because there's no good way to write such applications in Python. The deployment of Python GUI programs for deployment to desktops is a complete nightmare. PyInstaller, p2exe, pyfreeze have all attempted it but they either don't work with everything or needs massive amount of trial-and-error configuration which can completely break as soon as some extra (or newer version) package is required.

All Matlab has to do to keep a hold of it's share is improve the GUI, make it faster and nicer looking (like proper layout), and Python will be left in the dust by people currently looking to switch to it from Matlab.

6

u/mexiKobe Aug 06 '19

wait what? I was talking about MATLAB. Python is infinitely more portable

7

u/elbiot Aug 06 '19

Uh, all those are for distributing to people that don't have python installed. Surely matlab programs can't be distributed to people that don't have matlab installed, right?

1

u/SubliminalBits Aug 06 '19

You can. Just buy their compiler toolkit and you can build a binary that doesn't require a matlab license to run. Its the usual Matlab caveat of pay Mathworks absurd amounts of money, but it works fine.

1

u/I_Feel_It_Too Aug 07 '19

Oh, if we're playing that game (which I am ok with), there are Python compilers, too. They work just as "fine" as compiled Matlab, which is to say, there are pros and cons to both.

2

u/SubliminalBits Aug 07 '19

I agree. I just wasn’t sure if you were aware of the matlab option. It sounds like you were.

1

u/Mr_Again Aug 06 '19

I'm sure all the performance - oriented GUI programmers currently doing it in Python for some insane reason will be right over to matlab.

1

u/Feminintendo Aug 06 '19

But yeah the problem is when engineers and scientists only use it and try to write applications with it.

That's because there's no good way to write such applications in Python.

Surely you're not serious.

Python will be left in the dust by people currently looking to switch to it from Matlab.

I have never heard of anyone who has switched to Matlab because they wanted to. The only people I know who are proficient in other languages but who use Matlab do so because of a project lead who doesn't understand the sunken cost fallacy or because there is literally no other tool that does some very specific obscure thing that Matlab does. It is painfully obvious you are not among that group.

1

u/log_2 Aug 06 '19

Surely you're not serious.

Indeed, I am.

Python will be left in the dust by people currently looking to switch to it from Matlab.

I have never heard of anyone who has switched to Matlab because they wanted to.

Check you're logic there mate, you flipped it. That's ok, logic is hard!

1

u/Feminintendo Aug 07 '19

I think I am confused because I am having a hard time parsing this sentence:

Python will be left in the dust by people currently looking to switch to it from Matlab.

At any rate, I have a hard time imagining Python being "left in the dust" by anything, and, to reiterate, I don't know anyone who switched to Matlab from Python because they wanted to. My own perception, which I can't really back up with anything, is that to the extent Python will steal people away from Matlab, it won't really make a significant difference to the number of people using Matlab. In other words, Matlabbers gunna Matlab. I mean, I hope I'm wrong...

1

u/billsil Aug 07 '19

People switch to Matlab from Python because they're forced to use certain libraries (e.g., signal processing, Simulink, machine learning). My company doesn't like using it, but when it's better, fine...

1

u/Feminintendo Aug 07 '19

Yes, that makes sense. But it's a deal with the devil: you get to use that one obscure library that can do what nothing else can, but you have to use a heinous programming language and pay a lot of money.

1

u/I_Feel_It_Too Aug 06 '19

Not at all for numerical calculations / matrix math etc.

No, the language is grotesque for numerical calculations. It might be good at doing matrix computations, but that doesn't mean the language isn't hideous. And it isn't that good at matrix computations, either, because it's so shit at memory management, reading fucking plaintext from a file, anything having to do with the most elementary data structures, handling errors, ....

There are free alternatives to Matlab for literally anything that Matlab is good at that perform at least as good as Matlab does.

→ More replies (9)

0

u/[deleted] Aug 06 '19

[deleted]

4

u/mexiKobe Aug 06 '19 edited Aug 06 '19

Tensor operations are very easy with MATLAB. It’s just like any other matrix operation. I have no idea where you got this idea that you had to loop when N>2.

→ More replies (4)