NumPy – The High Performance Package for Scientific Computation

What is NumPy

NumPy (short for numerical Python) is the library package in Python for scientific computing in Python. It is a powerful Python library for computing numbers and analyzing data. NumPy is widely used for scientific computing in Physics, Chemistry, Biology, Astronomy, data analysis, machine learning, Natural Language Processing, and many more disciplines.

This page is under construction.

Why Use NumPy

Python provides lists that are good, general-purpose containers of data. Python lists can be used to build arrays; they can contain heterogeneous data (elements of different data types). Python lists are quite fast when used to perform individual operations on a handful of elements. However, these programs are slow for large amount of data.

Vectorization

NumPy implements vectorization, which produces programs that are free of any explicit looping, indexing, and iterations. These things are taking place “behind the scenes” in optimized, pre-compiled C-code.

Vectorization applies the operations on the whole array rather using loops and indexing in the code to cycle through the entire array. This technique makes the numerical computations that are more efficient, easier to write, and understand.

Broadcasting

Broadcasting is a term that is used to describe the implicit element-by-element behavior of operations. In NumPy, element-by-element operations are the “default mode”.

https://numpy.org/doc/stable/user/basics.broadcasting.html

Vectorization and Broadcasting techniques make the NumPy programs that are:

  • Easy to read and understand code: The programs are shorter and the operations are expressed in mathematical terms.
  • High in performance: The programs are significantly faster than code using explicit loops
  • Efficient in memory usage: NumPy programs are generally more memory usage efficient.

Let us look at the program example below to clarify these concepts.

As a simple example, consider the case of multiplying each element in a 1-D sequence by the corresponding element in another 1-D sequence of the same length. The data are stored in two Python lists, named “a” and “b”. The Python program multiplies the two by iterating over each element of the two lists.

The program also does the multiplication of two 1-D arrays using NumPy.

PROGRAM EXAMPLE: Why Use NumPy

Note that the NumPy program is simpler and intuitive because its uses of vectorization and broadcasting.

ndarrays

NumPy incorporates an array object, called ndarray, with lots of supporting functions that make the programs much faster and easier to use. NumPy programs using ndarrays are efficient in that they are fast and they consume less memory. When there are large quantities of “homogeneous” (same type) data) to be processed, NumPy is an excellent choice. For reference, click on the list below.

https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray

NumPy Import

All NumPy programs must start by importing NumPy using the following statement.

>>> import numpy as np.

The following pages review the basics of NumPy package.  We start with the introduction to Arrays.

Copyright © 2026 softwareprogramming4kids.com

All Rights Reserved

Verified by MonsterInsights