Why use NumPy?

NumPy code is much cleaner than "straight" Python code that tries to accomplish the same task. There are less loops required, because operations work directly on arrays and matrices. The many convenience and mathematical functions make life easier as well. The underlying algorithms have stood the test of time and have been designed with high performance in mind.

NumPy's arrays are stored more efficiently than an equivalent data structure in base Python such as list of lists. Array IO is significantly faster too. The performance improvement scales with the number of elements of an array. For large arrays it really pays off to use NumPy. Files as large as several terabytes can be memory-mapped to arrays, leading to optimal reading and writing of data. The drawback of NumPy arrays is that they are more specialized than plain lists. Outside of the context of numerical computations, NumPy arrays are less useful. The technical details of NumPy arrays will be discussed in the later chapters.

Large portions of NumPy are written in C. That makes NumPy faster than pure Python code. A NumPy C API exists as well and it allows further extension of the functionality with the help of the C language of NumPy. The C API falls outside the scope of this book. Finally, since NumPy is open-source, you get all of the related advantages. The price is the lowest possible—free as in "beer". You don't have to worry about licenses every time somebody joins your team or you need an upgrade of the software. The source code is available to everyone. This of course is beneficial to the code quality.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset