Python Is Python the Best Choice for Computational Physics?

AI Thread Summary
Python is highly regarded for computational physics due to its speed, versatility, and extensive libraries like SciPy and NumPy, which often outperform Mathematica in numerical tasks. While Mathematica excels in symbolic computation and offers superior plotting capabilities, Python's object-oriented nature and broader application range make it a powerful choice for many users. The integration of tools like Sage enhances Python's functionality for various mathematical computations. Additionally, Python is free and open-source, making it accessible for learners and researchers alike. Overall, Python is recommended for its practicality and effectiveness in computational tasks compared to other languages like Fortran or MATLAB.
Winzer
Messages
597
Reaction score
0
Hello, I have recently become interested in computational physics. I know a good deal of Mathematica. Recently I have heard great things about Python. My questions are:
1) How useful is Python in computation?
2) Would there be a better program to learn instead of Python for computation?
Any additional comments would be appreciated.
 
Technology news on Phys.org
If would have to pick "a couple" of languages to work with python would be one of them.
 
PerennialII said:
If would have to pick "a couple" of languages to work with python would be one of them.
Can you name the other ones?

Also, can someone tell me:
1)Two or more benefits of Python over Mathematica
2)Two or more disadvantages of Python over Mathematica
 
Winzer said:
Can you name the other ones?

Personally speaking, I'd concentrate on Python and C/C++.

Winzer said:
Also, can someone tell me:
1)Two or more benefits of Python over Mathematica

*: Speed. CPython, the standard distribution of Python that you can download from python.org, is built upon C. Hence modules like Numpy and Scipy have been able to produce code that is in many cases significantly faster than equivalent Mathematica code.

*: Python is an actual programming language. Mathematica, for all its wonderful uses, really isn't a serious language. Object orientation, for instance, is natural and easy to use in Python; although OOP is possible in Mathematica, it's ugly and cumbersome in an ungodly way.

*: Python is a much more powerful language.

*: It's free.

*: It's more popular than Mathematica.

*: It's got a much, much wider focus. For instance, Python will handle all of the numerical work Mathematica can do but can also do nifty, network-focused things with your data once it's been obtained. This is pretty much impossible with Mathematica.

Winzer said:
2)Two or more disadvantages of Python over Mathematica

*: Well, Mathematica's real strength is in symbolic computation. To the best of my knowledge, Python can't do symbolic computation at all.

*: Plotting in Python is poor in comparison to Mathematica, especially to version 7.0.
 
Winzer said:
Can you name the other ones?

Also, can someone tell me:
1)Two or more benefits of Python over Mathematica
2)Two or more disadvantages of Python over Mathematica

Thinking about tools which enable to carry out "research tasks" as effectively as possible with a wide range of applicability (thinking about code performance, "usability" of the resulting code and development time) would pick a medium level language like C++, then Python which is actually kind of "in between" due to its performance imho and then Mathematica [scripting wise that is] (followed closely by Matlab, but its necessity is shadowed a bit by Python with scipy and works, although it's very easy to pick up). After those would pick good old Perl for some raw data processing, but most tasks do with Perl can be done nicely with Python.
 
Here's a yet another reason to learn Python! Check the open source tool Sage http://www.sagemath.org/
It is a python-based tool that integrates various (powerful) open source tools for numerical computations, statistics, symbolic computations, number theory, algebra(as diverse as group theory, linear algebra, representation theory, commutative algebra, and algebraic geometry), ...

The integration of these tools under Python is exceptional in my opinion! There's a very useful "notebook" a la Mathematica! But much more powerful I'd say!

It got not only great plotting capabilities, but also interactive ones, including Java 3D, take a look at http://wiki.sagemath.org/interact
 
Is there a reason why I would learn Python over Fortran?
 
Winzer said:
Is there a reason why I would learn Python over Fortran?

Put it this way. In the two or three days you've spent asking other people's opinions, you could already have learned a sizeable and useful amount of Python.
 
  • #10
shoehorn said:
Put it this way. In the two or three days you've spent asking other people's opinions, you could already have learned a sizeable and useful amount of Python.

Oh good sir, who says I haven't been learning python? Not me.
 
  • #11
Winzer said:
Oh good sir, who says I haven't been learning python? Not me.

Neither did I. It was intended as a comparison with Fortran in the sense that in the few days you've been learning Python you've probably learned far more than you could have if you'd chosen Fortran.
 
  • #12
How about mathlab vs phython,which one is the best for a physics major?
 
  • #13
Winzer said:
Is there a reason why I would learn Python over Fortran?

You'll get a whole lot more done :wink: . Comparing languages and "stating" what is needed is always a bit arbitrary (at best), but in "general terms" when learning to do things and so forth Fortran isn't quite as useful as Python (unless everything in your field is written in Fortran for some reason or something similar). Fortran has its uses and Python its own, unless you have something in mind where you especially need something Fortran does very well Python is an animal would recommend. Not to downplay good old Fortran, I still need it :biggrin: .
 
  • #14
Qquantum1 said:
How about mathlab vs phython,which one is the best for a physics major?

Both.
 
  • #15
Qquantum1 said:
How about mathlab vs phython,which one is the best for a physics major?

matlab, maple, mathematica, etc... are all very good for symbolic and numerical calculations and for visualization (thanks to a dazzling array of specialized functions).

Python is more of a general purpose language... with a lot of useful functions imported through libraries and modules... and it's free and open source. For physics, there is this useful library http://vpython.org/

Note that Python (via the optimized numerical linear algebra library NumPy) has many Matlab-like functions and syntax.

If I were you, I'd learn both.

(One thing Python can do (that many other languages can't do as easily) is
interact with other programs... I've written Python (and Perl) programs that write Maple code... then a script can start Maple and execute it. If needed, Python can parse the output of the Maple program and do something else with it... e.g. send post-processed data to another program [like gnuplot].)
 
Back
Top