Is Python appropriate for algorithms focused on scientific computing? [closed]

My interests in programming lie mainly in algorithms, and lately I have seen many reputable researchers write a lot of their code in python. How easy and convenient is python for scientific computing? Does it have a library of algorithms that compares to matlab's? Is Python a scripting language or does it compile? Is it a great language for prototyping an algorithm? How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat? Is it OO based?

Sorry for the condensed format of questions, but I'm very curious and was hoping a more experienced programmer could help me out.

Asked by: Julian964 | Posted: 30-11-2021

Answer 1

How easy and convenient is python for scientific computing?


Does it have a library of algorithms that compares to matlab's?


Is Python a scripting language or does it compile?


Is it a great language for prototyping an algorithm?


How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat?


Is it OO based?


Answered by: Samantha182 | Posted: 01-01-2022

Answer 2

How easy and convenient is python for scientific computing?

Very! You should try attending the SciPy conferences (every year there's one in the US and one in Europe) to get a real feeling for that, but even just the rest of the site should give you some impression.

Does it have a library of algorithms that compares to matlab's?

I don't know matlab, but the amount of stuff available in/for Python is staggering.

Is Python a scripting language or does it compile?

Python is a language, and it offers many implementations (all open-source).

The most popular one, CPython, compiles sources to its own bytecode which its virtual machine then executes (the compilation is very fast and happens transparently when needed, but compiled files are typically stored on disk and recompiled only when needed). That's very similar to Java/JVM or C#/.Net, except the compilation step can be subsumed with the execution step (but of course you can have a build system which compiles ahead-of-time, if you want).

Jython compiles to JVM bytecode, which a JVM then executes; Microsoft's IronPython (their first fully open source project, I believe) compiles to CRL (".Net bytecode") which .Net and Mono can then execute. They both support both just-in-time and ahead-of-time compilation to their respective bytecodes.

PyPy can compile Python sources to many things, including (for a subset of Python) directly (ahead-of-time) to native machine language or (for all of Python) to an intermediate code which is then compiled to machine language in just-in-time fashion. PyPy is incredibly flexible in terms of the kind of build systems you can set up. (Its name comes from the fact that it's coded in Python itself, and that's surely still a plus in many terms, but the speed of the code it makes, and its flexibility, are its biggest strengths today).

These four implementations are all production quality at this time (historically, they became so in the order I've listed -- PyPy most recently, and actually pretty recently indeed, but I like what I see there very much these days).

Is it a great language for prototyping an algorithm?

I can't think of a better one; see chapter 18 of the Python Cookbook, especially the introduction by Tim Peters, for more. That intro is entirely readable in the Google Books link I just gave, and I really can't do it justice in what's already going to be a long SO answer; please click on the link and read that intro!

How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat?

When I first met Python, after browsing through the tutorial, I decided to give it a try when I had a free weekend with my family away: I'd devote one weekend (Friday 6pm to Sunday midnight, or, well, wee hours on Monday perhaps) to learning the language by doing in it a CGI web app to compute and show various kinds of bridge probabilities (as a bridge enthusiast, but known in the field mostly through my probability and computer work about it, it's a problem I've long loved: I learned Fortran back in my freshman year, though at that time as an EE major I wasn't supposed to do programming until junior year, by punching cards to solve that kind of problem;-).

Of course I didn't expect to finish the task from scratch in 54 hours or so (minus sleep time;-) while teaching myself the language and its library (CGI and the needed algorithms I already knew well), but I wanted to see how far I would get (evaluating Python vs the other languages I was a guru in at the time, mostly perl and C++).

Less than 24 hours later (admittedly having slept little that night, I was just too excited), I stepped back and had to admit that I was finished -- not only did my little CGI web app have all the functionality I had had in mind, but I had also made it able to give output in different natural languages by building from scratch a little templating system (I knew there were plenty -- that's why I named mine yaptu, "Yet Another Python Templating Utility" -- but I just didn't have time to learn anything outside of the language and standard library... rolling my own was faster;-).

That's when I irretrievably fell in love with Python. Not long after, I ended up leaving my existing high-flying career for a spell writing books and freelancing with Python, and a few years later I moved across an ocean and two continents to join one of the largest companies extensively using Python (my current employer, Google) -- in the meantime having re-married (to my current wife, Anna -- she was also co-author in one of my books and the first woman Member of the Python Software Foundation). Our "vanity" license plate reads P♥THON...;-). So, OK, I'm biased. But it all started with those <24 hours in which I accomplished more than I had hoped to do in >54 hours (despite being, like all SW developers, an incurable optimist whenever it comes to "how long will it take me to do X" for any SW-centered X;-).

Is it OO based?

Yes, but multi-paradigm (like C++... but even more than C++) -- you don't have to use classes when you don't need them, and it has reasonable support for functional programming too (definitely not as deep as "true" FP languages like Haskell, but still very useful for many tasks).

Answered by: Wilson189 | Posted: 01-01-2022

Answer 3

It bytecompiles, and then sends the bytecode through an interpreter.

Official Tutorial


You are now set.

Answered by: Kimberly872 | Posted: 01-01-2022

Answer 4

Answer your question one by one:

How easy and convenient is python for scientific computing?

One great point of python is that it provides very intuitive way of writing code. The powerful embedded data structure such as dictionary and list would help you a lot in scientific computing. Besides, as a dynamic language, you do not need to deal with many low level detail which you have to do in C.

Does it have a library of algorithms that compares to matlab's?

Indeed, python has a great number of library of algorithms. For example, you can use NumPy and SciPy to support large, multi-dimensional arrays and matrices compuation. And you can find more detail in those links:

  1. official site of numpy:
  2. wikipedia of numpy:

Besides, python also has library to support network analysis. For example, networkx library is a great tool for graph analysis.

Is Python a scripting language or does it compile?

Generally, python is designed as a scripting language. But there is also tools for compile, for example, py2exe. I recommend you to use python as a scripting language. I think you may have performance concern about python. And a usually applied solution is to write those performance critic module in c/c++, and glue them by SWIG.

Is it a great language for prototyping an algorithm?

Sure it is. With the rich support of embedded data structure, you can quick implement some complicated algorithm with shorter code compared to C/C++. Typical example is as following:

 //C++ loop a one dimensional array and print value
  const int N = 100; 
  int A[N];
  for (int i = 0; i < N; ++i)
      cout << i;

#python loop a one dimensional array and print value
for i in range(100):
   print i

And as a scripting language, you do not need compile, run, recompile, run, it would save you a lot of time.

How long would it take me to learn enough of it to be productive provided I know C well and OO programming somewhat? Is it OO based?

Python is different from C. You may find it is not very convinent to write c-style code in python. But python is easy to start, most syntaxes are just plain English. Moreover, there are some great tutorials for python. For example, dive into python is very nice for beginners.

Python provides mechanism for OO based programming.

Answered by: Hailey333 | Posted: 01-01-2022

Answer 5

I've used Python for 6 years for scientific computing. Having come from matlab/IDL, it was very easy to do the switch since it's also interpreted.

There are 3rd party tools such as SciPy and Matplotlib to help specifically with data analysis /visualization. Also, if you look in Amazon there are books targeting this audience.

Python is also very often used to teach programming because of it's simple yet powerful syntax.

Answered by: Kellan822 | Posted: 01-01-2022

Answer 6

If you know C and some object oriented programming you'll learn python very quickly - most of the key things in just a few hours of reading / tinkering with it. Here are the main differentiators: - Designed to be easy to learn quickly and to encourage writing readable code. - Has the fewest warts of any object oriented programming language. - Doesn't force you to write object oriented code however. - Makes it easy to write scripts that can be executed stand alone or imported into others.

Object Oriented features: - True polymorphism. Unlike C++ and derivatives such as Java you don't have to stand on your head to make your code polymorphic, generic and reusable - even in ways you didn't think about beforehand. This is because although it's strongly typed it's not statically typed. So as long as your objects have the expected methods or attributes that some piece of code wants, it'll work. This is known as duck typing.
- Introspection - so you can easily check if a method or attribute is present before accessing it. Also is great for debugging. - You can add attributes and even methods to objects at run time. Very malleable code. - Supports multiple inheritance.

Problems: - Typically faster than Ruby but sometimes slower than Java. - You have to get used to seeing the word self all over the place. - Hard for C style developers to let go of having to type curly braces and semi-colons. Seeing uncluttered code like that can make you feel like there's just something missing.

There's a programming style guide that all python developers are meant to follow:

There's a variant of it that's faster than the main version and supports an easy to use concurrency mechanism. It's known as Stackless Python because it does away with using the C stack. EVE Online is written in this language.

Here's an example of something I suppose could be considered scientific programming - adjusting sound waves - it's simply cool - scroll down to the bottom for source and see how relatively simple it is.

Answered by: Madaline681 | Posted: 01-01-2022

Answer 7

Is Python appropriate for algorithms focused on scientific computing?


Answered by: Daisy987 | Posted: 01-01-2022

Answer 8

You asked about compiled/interpreted. If your concern here was execution speed, there is an aspect of python that doesn't seem to have been covered explicitly---you can use tools like SWIG and boost.python to make your lightning fast C/C++ packages appear in your python as modules. Once you get to the module, it will run at the speed/efficiency of the underlying C/C++ implementation. Many modules are available that take advantage of this.

So, you get to do all the organizational stuff in clear, flexible, easy to learn Python, and then when you get to your heavy number crunching, you get to hand off the problem to a fast, efficient routine. You get the best of both worlds.

Answered by: Sophia215 | Posted: 01-01-2022

Similar questions

python - Which of these scripting languages is more appropriate for pen-testing?

Closed. This question is opinion-based. It is not c...

Help me find an appropriate ruby/python parser generator

The first parser generator I've worked with was Parse::RecDescent, and the guides/tutorials available for it were great, but the most useful feature it has was it's debugging tools, specifically the tracing capabilities ( activated by setting $RD_TRACE to 1 ). I am looking for a parser generator that can help you debug it's rules. The thing is, it has to be written in python or in ruby, and have a verbose mo...

Would python be an appropriate choice for a video library for home use software

I am thinking of creating a video library software which keep track of all my videos and keep track of videos that I already haven't watched and stats like this. The stats will be specific to each user using the software. My question is, is python appropriate to create this software or do I need something like c++.

python - How do I determine the appropriate check interval?

I'm just starting to work on a tornado application that is having some CPU issues. The CPU time will monotonically grow as time goes by, maxing out the CPU at 100%. The system is currently designed to not block the main thread. If it needs to do something that blocks and asynchronous drivers aren't available, it will spawn another thread to do the blocking operation. Thus we have the main thread being almost tot...

arrays - Most appropriate data structure (Python)

I'm new to Python and have what is probably a very basic question about the 'best' way to store data in my code. Any advice much appreciated! I have a long .csv file in the following format: Scenario,Year,Month,Value 1,1961,1,0.5 1,1961,2,0.7 1,1961,3,0.2 etc. My scenario values run from 1 to 100, year goes from 1961 to 1990 and month goes from 1 to 12. My file therefore has 100*29...

python - Numpy time based vector operations where state of preceding elements matters - are for loops appropriate?

What do numpy arrays provide when performing time based calculations where state matters. In other words, where what has occurred in earlier or later in a sequence is important. Consider the following time based vectors, TIME = np.array([0., 10., 20., 30., 40., 50., 60., 70., 80., 90.]) FLOW = np.array([100., 75., 60., 20.0, 60.0, 50.0, 20.0, 30.0, 20.0, 10.0]) TEMP = np.array([300., 310...

python extend or append a list when appropriate

Is there a simple way to append a list if X is a string, but extend it if X is a list? I know I can simply test if an object is a string or list, but I was wondering if there is a quicker way than this?

python - Finding appropriate cut-off values

I try to implement Hampel tanh estimators to normalize highly asymmetric data. In order to do this, I need to perform the following calculation: Given x - a sorted list of numbers and...

python - What is an appropriate way to datamine the total number of results of a keyword search?

newbie programmer and lurker here, hoping for some sensible advice. :) Using a combination of Python, BeautifulSoup, and the Bing API, I was able to find what I wanted with the following code: import urllib2 from BeautifulSoup import BeautifulStoneSoup Appid = #My Appid query = #My query soup = BeautifulStoneSoup(urllib2.urlopen("" + Appid + "&amp;query=" ...

python - Defining appropriate number of processes

I have a python code treating a lot of apache logs (decompress, parse, crunching numbers, regexping etc). One parent process which takes a list of files (up to few millions), and sends a list of files to parse to workers, using multiprocess pool. I wonder, if there is any guidelines / benchmarks / advices which can help me to estimate ideal number of child process ? Ie. having one process per core...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python