ndarray (NumPy)
The ndarray is NumPy's core object: an N-dimensional, fixed-size array of elements that all share one data type, stored in a contiguous block of memory. It is the foundation that the entire scientific Python stack is built on.
NumPy
Unlike a Python list, an ndarray holds elements of a single dtype packed tightly in memory, which is what makes NumPy fast: operations run as compiled, vectorized loops over that contiguous buffer instead of as slow Python iteration. Every array has a shape (its size along each axis) and a dtype.
Arrays are created with functions like np.array, np.zeros, np.arange, and np.linspace. Their size is fixed at creation — 'growing' an array actually allocates a new one — so you size them up front rather than appending in a loop.
Because the ndarray is the shared currency of the ecosystem, pandas Series, scikit-learn inputs, and image buffers are all ndarrays underneath, which is why understanding it pays off everywhere.
Syntax
np.array(object, dtype=None)Examples
Python
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a)Output:
[[1 2 3]
[4 5 6]]