NumPy Introduction

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.

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 uses what is referred to as vectorization. Using vectorization in the code results in the absence of any explicit looping, indexing, etc. in the code; 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 and easier to write understand.

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

Broadcasting

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

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

The same multiplication of two arrays using NumPy is also included in the program below:

As a simple example, consider the case of multiplying each element in a 1-D sequence with the corresponding element in another sequence of the same length. If the data are stored in two Python lists, a and b, we could iterate over each element.

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.

PROGRAM EXAMPLE: Why Use NumPy

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

NumPy Installation

The following is the procedure to install NumPy on your computer:

Step 1:

Download the latest version of Python from the link below:

https://www.python.org/downloads

To find Python version installed on the computer:

C:\Users\Your_Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.14>python -V

Step 2:

PIP Installation: PIP is a package manager for Python packages.

https://pypi.org/project/pip

Get the command prompt and type the following:

C:\Users\Your_Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.14>python -m pip install –upgrade pip setuptools wheel

To find what version of PIP is installed on your computer, use the following link:

C:\Users\Your_Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.14>pip –version

Step 3:

Install NumPy using the following link:

C:\Users\Your Name>pip install numpy

Matplotlib Installation

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. 

To display the results of NumPy programs graphically, it is a good idea to download and install matplotlib in addition to NumPy.

https://matplotlib.org/stable/install/index.html

  1. Type cmd in the task bar for the Search box.
  2. The command window will open.
  3. Type the following in the command window:

python -m pip install -U matplotlib

Your computer screen will show the progress of installation. At the end of the installation process, the installation program will indicate that the matplotlib is installed successfully as shown below:

Installing collected packages: matplotlib

Successfully installed matplotlib-3.10.8

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