Overview

NumPy (Numerical Python) is an open-source library that serves as the foundation for numerical computing in Python. Developed in 2005, its primary object is the ndarray (N-dimensional array), a fast and flexible container for large datasets in Python. The ndarray object provides more efficient storage and data manipulation compared to standard Python lists, especially when dealing with numerical data. This efficiency is critical for scientific computing, where large datasets and complex mathematical operations are common.

The library offers a comprehensive set of mathematical functions to operate on these arrays, covering areas such as linear algebra, Fourier transforms, and random number generation. These functions are highly optimized, often implemented in C or Fortran, allowing NumPy to achieve performance levels comparable to code written in compiled languages. This performance advantage makes NumPy an essential tool for data scientists, engineers, and researchers working with Python for data analysis, simulation, and algorithm development.

NumPy's capabilities extend beyond basic array manipulation. It supports broadcasting functionality, which allows operations between arrays of different shapes, simplifying code and improving performance. It also provides tools for integrating C/C++ and Fortran code, enabling developers to incorporate high-performance routines directly into Python applications. Many other prominent Python libraries, including Pandas for data manipulation, Matplotlib for plotting, and SciPy for advanced scientific computing, build upon NumPy's array object, making it a cornerstone of the Python scientific ecosystem.

For developers, NumPy offers a robust and well-documented API, facilitating the creation and manipulation of numerical data structures. Its extensive documentation on NumPy reference access provides detailed explanations of its functions and objects. The library is entirely free and open-source, maintained by a community of contributors, ensuring its continued development and accessibility for a wide range of applications, from academic research to industrial machine learning pipelines.

Key features

  • N-dimensional Array Object (ndarray): Provides a high-performance, memory-efficient array object for storing and manipulating large multi-dimensional datasets.
  • Broadcasting Functions: Enables arithmetic operations between arrays with different shapes, eliminating the need for explicit loops and improving code conciseness and performance.
  • Linear Algebra Routines: Offers a comprehensive set of functions for linear algebra operations, including dot products, matrix decomposition, eigenvalues, and solving systems of linear equations.
  • Fourier Transforms: Includes functions for performing discrete Fourier transforms (DFT) and inverse DFT, essential for signal processing and image analysis.
  • Random Number Generation: Provides various distributions for generating pseudo-random numbers, crucial for simulations, statistical modeling, and machine learning.
  • Universal Functions (ufuncs): Element-wise functions that operate on ndarray objects, implemented in C for high performance.
  • Connectivity with C/C++/Fortran: Tools to integrate existing C, C++, and Fortran code, enabling developers to leverage high-performance external libraries.
  • Array Manipulation: Functions for reshaping, splitting, joining, and stacking arrays, providing flexible tools for data organization.

Pricing

NumPy is an entirely free and open-source library. There are no licensing fees, subscription costs, or paid tiers associated with its use.

Tier Description Features Price (as of 2026-06-09)
Open Source Full access to all NumPy functionalities. ndarray object, broadcasting, linear algebra, Fourier transforms, random number generation, C/C++/Fortran integration. Free

For more details on contributors and community support, refer to the NumPy homepage.

Common integrations

  • SciPy: Extends NumPy's capabilities with modules for optimization, statistics, interpolation, and more advanced scientific computing. Refer to the SciPy Getting Started guide.
  • Pandas: A data manipulation and analysis library built on NumPy, providing DataFrames for structured data. Consult the Pandas documentation.
  • Matplotlib: A plotting library for creating static, animated, and interactive visualizations in Python. See the Matplotlib user guide.
  • Scikit-learn: A machine learning library that uses NumPy arrays as its primary data structure for input and output. Review the Scikit-learn documentation.
  • TensorFlow / PyTorch: Deep learning frameworks that can convert NumPy arrays to their respective tensor objects for neural network computations. For TensorFlow, see TensorFlow NumPy compatibility.

Alternatives

  • SciPy: A collection of numerical algorithms and domain-specific toolboxes built on NumPy, offering more advanced scientific computing functionality.
  • Pandas: A library for data manipulation and analysis, primarily known for its DataFrame object, which provides a tabular data structure.
  • TensorFlow: An open-source machine learning framework that includes its own highly optimized tensor objects and operations, often used for deep learning.
  • cuNumeric: A GPU-accelerated library that aims to provide a NumPy-compatible API for operations on NVIDIA GPUs, offering performance enhancements for suitable workloads.
  • JAX: A high-performance numerical computing library with a NumPy-like API, designed for high-performance numerical computation and machine learning research, supporting autodifferentiation and JIT compilation.

Getting started

To begin using NumPy, you typically install it via pip and then import it into your Python script. Here’s a basic example demonstrating array creation and a simple numerical operation:

# First, install NumPy if you haven't already
# pip install numpy

import numpy as np

# Create a NumPy array from a Python list
my_list = [1, 2, 3, 4, 5]
my_array = np.array(my_list)

print("Original array:", my_array)
print("Type of array:", type(my_array))

# Perform a simple element-wise operation (e.g., multiply by 2)
result_array = my_array * 2

print("Array after multiplication:", result_array)

# Create a 2D array (matrix)
matrix = np.array([[1, 2, 3], [4, 5, 6]])
print("\n2D Array (Matrix):\n", matrix)

# Get the shape of the matrix
print("Shape of matrix:", matrix.shape)

# Perform matrix addition with another array
matrix_b = np.array([[7, 8, 9], [10, 11, 12]])
sum_matrix = matrix + matrix_b
print("\nSum of two matrices:\n", sum_matrix)

This code snippet initializes a NumPy array, performs an element-wise multiplication, and demonstrates the creation and addition of 2D arrays. The np.array() function converts standard Python lists into NumPy's efficient ndarray object. The output shows the array's contents, its type, and the results of the operations, illustrating NumPy's fundamental usage for numerical tasks.