Skip to content
IT glossary
Data and MLUpdated December 3, 2026

NumPy

A Python library for numerical computing with arrays. It lets you work with whole sets of numbers at once, such as finding the average of each column or multiplying two matrices.

What NumPy gives you

NumPy is a Python library built around the ndarray, a multidimensional array. A one-dimensional array can hold a series of sensor readings. A two-dimensional array can hold a dataset with one sample per row and one feature per column. A color image can use three axes: height, width, and color channel.

An array is not just a Python list with a different name. Multiplying a list by 2 repeats its entries. Multiplying a NumPy array by 2 doubles each value.

Shape, data type, and vectorized operations

An array's shape tells you how many entries it has along each axis. For example, (4, 3) describes a two-dimensional array with four rows and three columns. Its dtype, such as int32 or float64, describes how each element is represented. For ordinary numeric types, NumPy stores values in a buffer rather than as individual Python objects.

When you write a * 2, NumPy runs the loop in compiled code instead of executing Python code for each element. This style is called vectorization. It often speeds up operations on large numeric arrays, but it does not make them free: an expression with several operations can allocate several temporary arrays.

Example: convert readings to different units

Suppose each row has a distance in meters followed by a duration in seconds. To convert the distances to centimeters and the durations to milliseconds, multiply each column by its own factor:

import numpy as np

readings = np.array([[2, 3], [4, 5], [6, 7]])
converted = readings * np.array([100, 1000])
# array([[200, 3000], [400, 5000], [600, 7000]])

This works through broadcasting. NumPy compares shapes from the last axis toward the first. At each step the sizes must match or one must be 1; missing leading axes count as size 1. Here (2,) acts like (1, 2), so each row gets the same pair of factors without NumPy first building a full array of repeated factors.

When to use it and what interviewers ask

NumPy is useful for feature preparation, simulations, and linear algebra. If the job is to join tables by key or group rows by a named column, pandas is usually a better fit. You can still use NumPy for the numerical computations on data extracted from a table.

In interviews, practice predicting output shapes. For a two-dimensional a, a.sum(axis=0) removes the row axis and returns one sum per column. For two-dimensional arrays, a * b multiplies elements, while a @ b computes a matrix product. Also check whether a result shares memory with its input: a[:, 0] is a view, so changing values through it changes a. By contrast, selecting rows with a list of indices, as in a[[0, 2]], produces a copy when read.