Introduction to NumPy

NumPy is a Python library created in 2005 that performs numerical calculations. It is generally used for working with arrays.

NumPy also includes a wide range of mathematical functions, such as linear algebra, Fourier transforms, and random number generation, which can be applied to arrays.

What is NumPy Used for?

NumPy is an important library generally used for:

  • Machine Learning
  • Data Science
  • Image and Signal Processing
  • Scientific Computing
  • Quantum Computing

Why Use NumPy?

Some of the major reasons why we should use NumPy are:

1. Faster Execution

In Python, we use lists to work with arrays. But when it comes to large array operations, Python lists are not optimized enough.

Numpy arrays are optimized for complex mathematical and statistical operations. Operations on NumPy are up to 50x faster than iterating over native Python lists using loops.

Here're some of the reasons why NumPy is so fast:

  • Uses specialized data structures called numpy arrays.
  • Created using high-performance languages like C and C++.

2. Used with Various Libraries

NumPy is heavily used with various libraries like Pandas, Scipy, scikit-learn, etc.

Import NumPy in Python

We can import NumPy in Python using the import statement.

import numpy as np

The code above imports the numpy library in our program as an alias np.

After this import statement, we can use NumPy functions and objects by calling them with np.


  • If we import NumPy without an alias using import numpy, we can create an array using the numpy.array() function.
  • Using an alias np is a common convention among Python programmers, as it makes it easier and quicker to refer to the NumPy library in your code.