Master 1D vectors, 2D matrices, and 3D tensors built on NumPy's ndarray object.
The core data structure in NumPy is the 'ndarray' (N-dimensional array). It represents a multi-dimensional table of elements of the same type, indexed by a tuple of positive integers.
1D is a row of mailboxes (vector). 2D is a postal sorting grid with rows and columns (matrix). 3D is a tall cabinet holding multiple shelves of grids (tensor).
1D arrays have 1 axis (length). 2D arrays have 2 axes: axis 0 (rows) and axis 1 (columns).
matrix = np.array([[1, 2], [3, 4]])Visualize multidimensional ndarrays in full 3D space with depth, row, and column slice planes.
tensor = np.arange(10, 37).reshape(3, 3, 3)Full 3D ndarray Tensor. Shape: (3, 3, 3) • 27 elements in RAM
arr = np.array(1, 2, 3)arr = np.array([1, 2, 3])Elements must be passed as a single list `[1, 2, 3]` or tuple inside `np.array()`.
Solve the objective below using NumPy vectorized syntax
Create a 2D matrix containing `[[1, 2], [3, 4]]` and print it.
[[1 2]
[3 4]]