Everything in NumPy revolves around one object: the ndarray (n-dimensional array). It's a grid of values, all of the same type, indexed by a tuple of integers. A 1-D array is a vector, 2-D is a matrix, and you can go to any number of dimensions.
Dimensions
import numpy as npa = np.array([1, 2, 3]) # 1-D — a vectorb = np.array([[1, 2, 3], [4, 5, 6]]) # 2-D — a matrix (2 rows, 3 cols)a.ndim # 1 number of dimensions (axes)b.ndim # 2b.shape # (2, 3) size along each axisb.size # 6 total elements
Axes
Each dimension is an axis. For a 2-D array, axis 0 runs down the rows and axis 1 runs across the columns. This idea returns constantly — reshaping, joining and aggregating all talk in terms of axes.
One type per array
Unlike a list, an ndarray is homogeneous — every element shares one dtype. That uniformity is exactly what lets NumPy store it compactly and process it fast:
np.array([1, 2, 3]).dtype # dtype('int64')np.array([1.0, 2, 3]).dtype # dtype('float64') — promoted to fit allnp.array([1, "a"]).dtype # dtype('<U21') — everything becomes a string
Key takeaways
- 01The ndarray is a grid of same-typed values indexed by integers.
- 021-D is a vector, 2-D a matrix, and arrays can have any number of dimensions.
- 03ndim/shape/size describe the structure; each dimension is an axis (0=rows, 1=cols).
- 04Arrays are homogeneous — one dtype throughout — which is what makes them fast.
