9
$\begingroup$

So I've been debating whether or not I should bother learning Python. From speaking with my professors, Matlab seems to be the common language used in applied mathematics/computational science as far as academia is concerned; while in industry, my professors (esp. those who have worked in industry) have said learning c++ is the safest route.

I'd like to hear from those of you, in both academia and industry, as to whether I should even bother with Python, or just get really good at what I know (MATLAB and C++) for the time being.

Background

I'm currently an undergrad in my last year, studying maths with a specialization in computation. I'd like to pursue grad school and stay in research (I've never seen myself enjoying teaching) or work in a lab. Both of those are ideal. As to what areas of research, probably something along the lines of numerical analysis or probability. In case plan A doesn't work out, I would be open to work in industry, as long as preparing myself for industry doesn't take away too much time from school. So, I figured I should learn the languages that are common in industry just as a backup. But this is also why I am conflicted. I can't study every language or prepare myself for every possibility since that would take way too much time.

$\endgroup$
2
  • 1
    $\begingroup$ Your question is a good one, but probably a bit too open-ended and vague. What discipline are you studying, and what do you think you might want to do? $\endgroup$ Commented Jan 30, 2013 at 6:05
  • 1
    $\begingroup$ For an example of things that can be done with Python that wouldn't work well in MATLAB or pure C++: epubs.siam.org/doi/abs/10.1137/110856976. (shameless self-promotion alert) $\endgroup$ Commented Feb 8, 2013 at 9:53

6 Answers 6

14
$\begingroup$

A difficulty with any of these types of questions is that the answer is highly community-dependent.

To answer some of your questions in haphazard order:

MATLAB is used a lot both in academia and in industry. One of the reasons it's used quite a bit in industry is because it is taught in academia. I know for a fact that MATLAB is used at Lincoln Laboratory and in DuPont's research and development divisions.

There are software packages written in Python that are good at symbolic computation, such as sympy and SAGE. Depending on your particular interests, feature requirements, and personal preferences, Mathematica (or Maple, or other computer algebra systems) may be superior to these packages.

MATLAB has a Symbolic Math Toolbox that can be used for some symbolic computations, but its symbolic manipulation capabilities, in my experience, are weaker than Mathematica and Python. Some symbolic manipulation could theoretically be done in C++, but it is unwieldy. MATLAB is also not a good general purpose language. It does linear algebra and numerical mathematics well, but it does not have good input/output capabilities. It does not have good parallel capabilities (even though there are variants like parallel MATLAB, MATLAB Star-P, and the Parallel Computing Toolbox) compared to C++ or Python. Even its graphics capabilities could use some work. MATLAB is also expensive unless you're affiliated with an institution that has a license. Each toolbox is expensive to purchase, and generally costs on the order of hundreds to thousands of dollars.

Mathematica does numerical computation in addition to symbolic computation. I haven't seen people use it for numerical computation as much as I have seen people use Python and MATLAB for numerical work. It too has parallel capabilities, but won't scale to large supercomputers.

Python is a good general purpose language that is regarded as easy to learn and usable. It is used on large supercomputers (see, for instance, PyClaw, petsc4py, mpi4py, and others), and scales well. It also has highly regarded numerical packages (such as NumPy and SciPy); a large, active community; good input/output processing capabilities; and good graphics libraries, along with a large repository of libraries (check out PyPI). It is free, compared to the proprietary packages mentioned above. You can find most of the functionality of MATLAB or Mathematica in freely available Python packages. The main disadvantage of Python is that it tends to be slower than compiled languages like C++, although this disadvantage is diminishing with the continued development of Cython, Numba, and PyPy; it can also be mitigated by replacing slower Python code with C (or C++, or Fortran) code and appropriately written Python wrappers. Being interpreted, many people report higher productivity with Python than compiled languages. It is quite popular, and probably worth learning if you have time.

C++ is a complicated language, and its use in computational science is controversial. Its large feature set can make it easy to write software that is difficult to maintain and takes forever to compile. However, used judiciously, features such as templating and operator overloading can be employed to great effect, as it has been in projects like deal.II, Blaze, and Elemental (among others). C++ has a steep learning curve when it comes to its advanced features, and I've heard anecdotal reports of people taking years to feel like they've learned the full language. Nevertheless, it is also a popular language, despite the usability concerns and the complicated feature set. It is probably worth learning, if only to make yourself more employable; its main competitors in computational science are Fortran and C, which are also worth learning. C and C++ are separate languages, and I advise you to learn them separately, however often you see people write "C/C++".

Whatever you decide to learn will be based on what you actually need. Sure, it's nice to learn both Python and C++, but given time and resource constraints, you're probably only going to learn what you'll actually need to use, and that depends on the community you work in.

$\endgroup$
4
  • $\begingroup$ So as far as academia is concerned, would you say its better to invest time learning Python instead of C++? $\endgroup$ Commented Jan 30, 2013 at 22:13
  • 1
    $\begingroup$ Again, that all depends. I'm still more on the academic side of things, and I use Python all the time. I also still have to use C++ for work written in that language. My personal opinion is that learning Python first will probably pay off more quickly for you than if you learned C++ first, but I don't know what probabilists/stochastic processes/combinatorics people use, so your mileage may vary. $\endgroup$ Commented Jan 31, 2013 at 2:29
  • $\begingroup$ I would agree with Geoff that learning python first is a good idea, as it will get you going much faster. C++ is a good language, but the learning curve is significantly higher and learning it half-heartedly is arguable worse than not learning it at all. $\endgroup$
    – LKlevin
    Commented Jul 31, 2015 at 8:41
  • $\begingroup$ "C++ has a steep learning curve when it comes to its advanced features, and I've heard anecdotal reports of people taking years to feel like they've learned the full language". Yes I couldn't agree more. I think that any programmer worth his salt should learn c/c++ some time in his or her life, but it will definitely take you 10000 hours to really feel like an expert with them. +1 $\endgroup$
    – James
    Commented Jul 31, 2015 at 10:23
11
$\begingroup$

As Misha and Geoff Oxberry pointed out, Mathematica really has a different focus (just because you can pound in a nail with a screwdriver doesn't mean you should). So I take your question as being "If I know Matlab, why should I learn Python?" [Edit: and so, apparently, did you.]

For all intents and purposes, Matlab is the English of scientific computing -- with all the positive and negative connotations this analogy entails. One specific good point is that Matlab code is likely to be useful (i.e., executable as well as understandable) to more people than code in any other language is. (This is the main reason I provide Matlab codes for all my algorithms.) Also, the Matlab desktop can be really useful while prototyping, especially the ability to run bits of code (cells) directly from the editor, as well as the built-in profiler.

That being said, if you do want to learn another high-level language for fun and profit, you could do worse than Python. Some reasons in addition to what Geoff listed:

  • It is much easier to interface with external programs and libraries in Python. No more mex files!

  • If you're away from your desktop, it's much easier to get Python+NumPy/SciPy up and running than to get access to a Matlab license.

  • The main reason Matlab is faster than NumPy is that it bundles optimized vendor libraries for linear algebra (MKL, ACML). It is possible (if a bit tedious) to build your own NumPy and link it against the same libraries to get nearly the same performance (and multithreading) as Matlab for linear algebra, plus the better performance of Python for everything else. (Although that of course requires a license even for academic use, thus negating the free software bonus, it is still an interesting option to have the same code working on an employer-sponsored accelerated install in the office as well as an off-the shelf install on your home machine or notebook.)

  • While Matlab's toolboxes are one of its selling points, there are a few areas where Python is way ahead; in particular, SymPy and FEniCS beat the Symbolic and PDE toolboxes by a wide margin.

  • Don't forget the fun part (semantic whitespace and name binding notwithstanding): I've seen several colleagues getting bitten by the Python bug, and there is really something strangely satisfying in writing your algorithm in Python that isn't there in Matlab (although that might just be the joy of learning a foreign language) :)

(If you do start with NumPy, you might find this page helpful.)

$\endgroup$
0
4
$\begingroup$

Python may be replacement for both c++ and Matlab. It is well spread in both academia and industry. In industry it is sometimes used as a glue for lower level languages, mostly c/c++. Mathematica is completely another story. Its main advantage is where all other mentioned (c/c++; Matlab; Python) are not good: in symbolic computations.

So, all four are completely different: c++ is old and stable relatively low level programming language; Python is new and evolving high level computer language; Matlab is a numerical computational environment with a strong accent on vector algebra (though it is able to do more or less everything); Mathematica is a computer algebra system with a strong accent on symbolic computations (the same remark as with matlab). Thus, they are not competitors.

$\endgroup$
3
  • $\begingroup$ Indeed; I am often puzzled (and sometimes amazed) when I see people use Mathematica for scientific computing... $\endgroup$ Commented Jan 30, 2013 at 21:46
  • $\begingroup$ @ChristianClason and Misha: it is a misconception that Mathematica is primarily a computer algebra system. If you look at how people actually use it, most of it is not symbolic algebra, and in several numerical fields it is competitive with tools like MATLAB and R. (Personally I'd choose Mma over these other two for most numerical data processing tasks, but that's of course a personal preference.) In some areas, like numerical integration or visualization, it seems to be ahead of MATLAB. In others like PDE solving it's way behind. $\endgroup$
    – Szabolcs
    Commented Dec 8, 2013 at 3:42
  • $\begingroup$ For someone whose only interest is in numerical computing, Python is an alternative to MATLAB that is a relatively high level language that is similar in its ability to make use of library routines to handle standardized computations involving linear algebra, Fourier transforms, special functions, etc. Yes, Python is much more broadly applicable, but it does cover everything you might do in MATLAB. $\endgroup$ Commented Jul 31, 2015 at 16:14
4
$\begingroup$

I know your question is about the use of python, but you said that you were interested in "numerical analysis or probability." I don't know if you have considered R, but it is designed specifically for this kind of work. R is a very powerful language for probability and statistics, and has a very large and active user base of mathematicians and scientists.

R is different from Matlab in the sense that it is open-source, has a statistics focus, and makes some very impressive plots (see ggplot2). You can do nearly everything in R that you can do in Matlab, but my favorite aspect is the user contribution. Most of the contributed libraries are written by scientists and published in a statistical journal. They also have extremely well written guides (called references and vignettes). My new favorite library gives CUDA support built on the CULA libraries (free for academic use). There exists a prodigious amount of methods for probability theory as well (see here).

Anyway, R is definitely designed specifically for your line of work, so check it out and consider adding it to your toolkit :) Remember, your can execute R scripts within Python, and Python scripts within R, and easily capture the outputs.

Best of luck!

$\endgroup$
3
$\begingroup$

Others have already commented at length and in more depth than I will attempt here. However, I would like to highlight one point once more: it depends on your community. For example, if you are working on an electrical engineering project, chances are that you'll be using matlab; the same may be true if you are a numerical analyst wanting to verify your convergence rate estimate on a simple model problem.

On the other hand, if you're into scientific computing proper (e.g., simulating flow around an airfoil, simulating nuclear fusion in a plasma, simulating convection in the earth mantle) or into developing numerical methods with such applications in mind, then the lingua franca is C++. Every large scale scientific computing package is today written in C++ (or C), for better or worse, and this is how it's going to stay for a long time to come. To name just a few examples, PETSc and the incredibly large and diverse Trilinos packages are written in C and C++, respectively. Among the large open source finite element libraries I can think of (libMesh, deal.II, oofem, freefem) every single one is written in C++. Among the visualization programs, the two largest ones (Visit and Paraview) are written in C++. I could extend the list.

The point being that if you are content with small scale simulations, people use one language, but whenever it comes to serious, maybe parallel computations, they all use something else. It's a community thing for sure, but also with being interoperable -- if PETSc and Trilinos are written in C and C++, then I (being the author of deal.II) can't easily choose any other language even if I wanted to because I need to work with PETSc and Trilinos.

$\endgroup$
2
  • 1
    $\begingroup$ To be fair, there are many PETSc users coming from Fortran, and quite a few from Python. C is easy to call from almost any language, though mixed-language programming comes with its own set of challenges and I don't recommend it very often. The issue of where in the stack your code resides is also too frequently overlooked. End-user applications should make different software design choices than system-level libraries, for example. $\endgroup$
    – Jed Brown
    Commented Feb 1, 2013 at 4:16
  • $\begingroup$ That's fair. But it's nevertheless true that the more recent instances of software used in large-scale computations is overwhelmingly written in C and C++ these days (older hold-outs written in Fortran notwithstanding). $\endgroup$ Commented Feb 1, 2013 at 4:23
1
$\begingroup$

To add my two cents, I have had both recent academic experience (a fresh PhD grad :) ) and industry experience (a surveying equipment manufacturer).

We do plenty of numeric computations on weak embedded processors (think mobile phone processors). Apart from there being no MATLAB for ARM, C++ is king in this world - many embedded compiler suites don't include FORTAN!

Whilst we do have a limited number of MATLAB licences, the requirement to make a product drawing 2 Watts of power skews our development work in favour of C++, (experimenting aside).

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.