9. Numerical Python: NumPy and SciPy#
9.1. Scientific computing and numerical analysis#
Python is a powerful, general-purpose programming language. It provides tools that make Python the premier language for scientific computing.
But what is scientific computing? It is the collection of tools, techniques, and theories required to solve mathematical models of problems in science and engineering on a computer. It uses numerical analysis and simulations instead of traditional experimental or theoretical means to study problems that are too difficult, impossible, or expensive. Scientific computing spans all the sciences with strong links to numerical analysis, computer science and software engineering.
And what is numerical analysis? It is the study of algorithms that use numerical approximation for the problems of mathematical analysis. It is the study of numerical methods that are used to find approximate solution for problems that are very difficult or impossible to solve. It provides us with practical results for actual application, as well as insights for designing, modification, and invention with many applications in engineering and physics.
Two of the most popular Python modules for performing scientific computing are NumPy and SciPy. They bring the computational power of languages like C and Fortran to Python and are used to perform various operations on the data.
9.2. NumPy and SciPy#
NumPy (Numerical Python) is a library in Python developed for fast and efficient storage and manipulation of arrays and is fundamental for all scientific computing. As electrical engineers, we think of data as multidimensional arrays of numbers. Data can be collections of sensor recordings, images, videos, or any numerical recording. It is very important to be able to store and manipulate these arrays of data efficiently. NumPy is very fast and is much more efficient than Lists. Due to the use of vectorization, NumPy performs matrix operations more efficiently by avoiding many for loops. However, NumPy is mostly used for basic operations such as sorting, indexing, and elementary functioning on the array data type.
On the other hand, SciPy (Scientific Python) is a library that uses NumPy for more mathematical functions. SciPy uses NumPy arrays as the basic data structure, and comes with modules for various commonly used tasks in scientific programming, including linear algebra, integration (calculus), ordinary differential equation solving, and signal and image processing.
Although NumPy and SciPy are conceptually different, they have similar functionalities. Their combined functions are necessary for mathematical computations.