NumPy for relatively simple computations

Denni_Denny report abuse

I often see that people use NumPy package for doing relatively simple math. Isn't this redundant? Why they cannot use just pure Python?

Answers

srSikh report abuse

Because NumPy gives a performance boost. It is faster and more efficient to do the same computations using NumPy compared with pure Python.

Denni_Denny report abuse

Why NumPy is more efficient?

srSikh report abuse

The computations in NumPy are highly optimized. One of the most important things is that NumPy works with vectorized computations which are more efficient that the same computations in an unvectorized form.

Denni_Denny report abuse

And what vectorization means?

srSikh report abuse

It can be described as mathematical operations applied to the entire arrays (for example, NumPy arrays) instead of the individual elements of the arrays.

Denni_Denny report abuse

There is a good article on Wikipedia - https://en.wikipedia.org/wiki/Array_programming . Also, you can read more about NumPy, for example, this chapter of the NumPy tutorial - https://www.oreilly.com/library/view/python-for-data/9781449323592/ch04.html .

007_agent report abuse

Can there be situations where NumPy is less effective than pure Python?

srSikh report abuse

Probably any computation is more optimized in NumPy. Maybe some very simple calculations will take the same time in Python and in NumPy. But NumPy is not only optimized for speed, it also gives memory benefits. So, I would recommend using NumPy for all mathematical computations.

Add Answer

Need support?

Just drop us an email to ... Show more