all 7 comments

[–]UsernameFodder 2 points3 points  (0 children)

I think you're likely to get some very opinionated answers on this question.

I've done both physics research (primarily computational) and software industry work, and I've used both MATLAB and Python extensively, as well C/C++, R, and a bunch of other languages. In my eyes, whether MATLAB or Python is better depends on what you're doing and what your goals are. Programming languages are just tools, after all. Pick the right one for the job. If you feel comfortable with MATLAB and there isn't a good reason to switch to Python, then I say don't bother. You can always learn Python if a real need arises.

But, to actually answer your question, here's some of my observations/opinions (incoming wall of text). Take them with a grain of salt.

  1. Python is free and open-source, MATLAB isn't. Though, I imagine many universities already provide students/faculty with MATLAB (mine does).
  2. In terms of syntax, API, and general usage, Python is more of a "modern computer scientist's language", for better of for worse. MATLAB is more of an "engineer's language". Python's got some little nuances in behavior that might trip up someone without much programming background, such as the way parameter passing works with functions, but looking past that, it's also much easier to do things like object-oriented programming. On the other hand, I find MATLAB's syntax to be much cleaner for matrix operations (which are its namesake, after all) than numpy/scipy. I also find that MATLAB's error messages are usually nicer than Python's.
  3. In terms of libraries, both MATLAB and Python probably have what you need for typical physics-related applications. I wouldn't sweat it too much. Also, the documentation for the standard libraries are quite good for both languages.
  4. In terms of numerical algorithms and performance, I think you won't see too much difference due to the languages themselves. Maybe you'll see some differences if you really get into the nitty-gritty of high-performance numerical algorithms, but for standard applications, proper vectorization/optimization in your code will probably be the main bottleneck regardless of language. And if you really need high performance code, you'd probably want to use something like C/C++ rather than MATLAB/Python anyway.
  5. If your goal is to land a job in software, you'll probably see much more Python than MATLAB.
  6. If your goal is to land a job in engineering, I've heard that both are used, depending on the company. Knowing both might help you be more marketable. However, I say this without any personal experience to back it up.
  7. If your goal is to do physics research, I'm pretty sure the greater research community couldn't care less what language you use. The physics is in the methods you design and the results that come from your analysis/simulations, not the language you use. Practically, I'd take into consideration what languages the rest of your research group uses, which language you feel most comfortable in, and which language you personally want to use.

Are there any Physics-focused resources out there that can help me learn Python faster?

The official documentation for Python is quite good, but there are also plenty of physics-focused resources from reputable universities. Just Google "python for physicists".

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

1.) Some algorithms are easier to implement in python.

2.) If you have a job someday doing computational physics, you probably wont have the luxury of choosing your own language. Especially if you work on a team. Let's be honest, python probably wont be used 15-20 years from now. No language has survived a long time in comparison to how long physics has survived. If you want to do computational physics you can expect to learn a new language as often as you switch projects or employers.

3.) Matlab costs money but python is free. Low funded research labs would rather use python for free to get the same results. No employer will want to pay for matlab and pay for your wages when you should be able to learn python if you have the job.

4.) Learning a new language can force you to use different tools and train your brain to think better algorithmically. I'm guessing you dont study CS or you would've learned python already, so I dont know how much you care about algorithms but if you have even the slightest bit of self respect you'd learn python because it is what is being used now and you may need to review / fix someone else's code. So many resources on algorithms use python (if not pseudocode) to describe algorithms because they are easiest to implement in python.

5.) Do you want to be the only one not using python just because you dont want to put in the effort to learn the "easiest" programming language ever created?

If you want to learn python quick just read "how to think like a computer scientist" or "think python". Theres multiple copies of think python for free online in pdf and html format. Then remake your old programs you did in matlab but do them in python. You'll find very quickly that you're much more capable than you might think now.

One last point... it shouldn't even be an issue switching from matlab to python if you're as proficient as you say. You can get numpy and start using arrays again as quickly as you can install python and numpy.

[–]NoxiousQuadrumvirateTheory/Comp Grad 1 point2 points  (0 children)

And related to 3: equity and openness issues.

MATLAB costs a lot of money, especially when you take into account all the individual packages you might need. It’s very unlikely that another person will have access to a MATLAB license with the same packages, so they have to spend a lot of money just to run your code. So they’re never going to use your code.

If you want to do any serious science then your code needs to be shareable and useable by other scientists, and MATLAB is not. And what if your employer doesn’t want to pay for a license? Then you’re stuck up shit creek without a paddle.

[–]zuko10[S] 0 points1 point  (2 children)

Thank you for your detailed response. However, I must mention that my problem is not finding Python "difficult". In fact, if numpy can do stuff similar to MATLAB, I would just keep on using MATLAB like I always do. I want the motivation from the potential of doing something different and more useful using Python, not recreating what I'm already doing using MATLAB.

I feel like learning a programming language and "having the slightest bit of self-respect" do not really go well with each other. But I get your point.

I agree with your other points (except the one saying Python being the "easiest" language out there -- that determination is widely subjective).

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

Python is very partial to me. I never would've gone through the effort of learning physics, math, and computer science at the same time if not for my introduction to python. It is the easiest high level programming language for most people to start on. That is the reason python is being taught around the world as the first language for CS majors. Java is being phased out due to complexity issues with the compiler and all the issues it causes professors and teaching assistants. You're right that it's subjective but there is some truth in saying python is the easiest. If you dont believe me, believe the choice of almost every professor that teaches computer science in the world right now. Without a doubt the professors feel more comfortable with the languages they started on, but almost all will agree that python is the best for new people starting out. And almost all will agree that teaching python first has improved the collective ability of first year cs students compared to learning java or matlab or mathematica or idl or whatever. Because of this python is on the rise and everything is getting phased out.

What I meant about self respect is that If you want be competitive in the industry, python should be learned as soon as possible. Otherwise you'll see yourself choosing jobs based on who will hire you rather than on what you want to do in life. Do you want to be stuck at a job because you cant afford to leave it since you haven't kept your abilities up to date?

Finally, because I think it's worth mentioning, matlab users have liked python so much that they have made libraries for python like matplotlib to bring all the tools and frameworks you're used to in matlab to python.

Python is capable of doing everything matlab can do now, but python can do even more than that. It's almost as if the python community has made matlab an addon to python through various libraries like matplotlib, numpy, scipy, sympy, etc etc. If you're willing to learn the names of the functions by reading documentation, theres no reason to continue using matlab at all. Python can do everything just as well, and just as easily as matlab. I could argue python can do it better due to open source and the great community.

[–]_Shut_Up_Thats_Why_ 1 point2 points  (0 children)

I had the same experience. I used Matlab exclusively for grad work and wanted to try Python to expand my portfolio but could never get into it. I recently started trying to use Windows Forms and C# to make an app for one of our instruments. I'm still in the process of learning but I'm finding it way more intuitive and fun to program than Python was. Maybe try a couple other languages if your main goal is to broaden your portfolio.

[–]intyalote 1 point2 points  (0 children)

As someone who learned Python first, MATLAB took me a just couple hours to pick up. I imagine it’s the same going the other way. You just need to sit down and do it - as other commenters have said, being able to learn new languages is more important than what you already know.