What is NumPy in Python

The Python programming language provides a rich set of high-level data structures such as lists for enumerating a collection of objects. However, these structures are not ideally suited for high-performance numerical computations. For example, lists are very flexible but also slow to process in numerical computations. In the mid-90s, an international team of volunteers started to develop a data-structure for efficient array computation. This structure evolved into what is now known as the N-dimensional NumPy array.

The NumPy package, which comprises the NumPy array as well as many other mathematical functions, has found wide-spread adoption in academia, and industry, including in data science. In the Python world, NumPy arrays are now the standard representation for numerical data.

Basic Usage

To start using Numpy, you must first import the package in your working environment. The code examples below will assume that NumPy is imported as follows:

import numpy as np

To see that it is imported properly, you can check its version as below:

>>> import numpy as np
>>> np.__version__
'1.12.0'
>>>

The NumPy ndarray

One of the key features of NumPy is its N-dimensional array object, or ndarray. Arrays are similar to lists in Python, except that every element of an array must be of the same type, typically a numeric type like float or int. Arrays make operations with large amounts of numeric data very fast and are generally much more efficient than lists. The array has some important characteristics:

This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.

Related Downloads