Cheat sheets
NumPy cheat sheet
Quick reference for NumPy: creating arrays, indexing, vectorized operations, and statistics.
Create arrays
np.array([1, 2, 3])- Creates an array from a list.
np.zeros((3, 3))- Array of zeros with the given shape.
np.arange(0, 10, 2)- Sequence with a fixed step.
np.linspace(0, 1, 5)- N evenly spaced values in a range.
Index and reshape
arr[1:3]- Slicing: selects a range of elements.
arr[arr > 5]- Boolean indexing: filters by condition.
arr.reshape(2, 3)- Changes the array's shape without copying data.
arr.T- Transposes a 2D array.
Vectorized operations
arr + 1- Adds a scalar to every element, no loop.
arr1 + arr2- Element-wise addition between two arrays.
arr * 2- Multiplies every element by a scalar.
np.dot(a, b)- Dot product between two vectors.
Statistics
arr.mean(), arr.std()- Mean and standard deviation.
arr.sum(axis=0)- Sums along a specific axis.
np.linalg.norm(arr)- Magnitude (Euclidean norm) of a vector.