NumPy Cheatsheet - NumPy Functions & Array Operations Reference
This reference is for developers who frequently process arrays in Python, from quick data cleaning to embedding matrix math: creating arrays with np.array/np.zeros, pulling out data by index and slice, reshaping, drawing statistics with sum/mean, and matrix multiplication with a @ b. Unlike a bare API manual, entries follow the practical chain of create → select → reshape → compute → save. After reading you should be able to pick the right function for each stage and dodge the most common broadcast and view-vs-copy pitfalls.
Array Creation 9
np.array([1, 2, 3])np.zeros((3, 4))np.ones((2, 3))np.arange(0, 10, 2)np.linspace(0, 1, 5)np.eye(3)np.random.rand(3, 3)np.random.randn(3, 3)np.random.randint(0, 10, (2, 3))Indexing & Slicing 6
a[0]a[1:3]a[a > 5]a[[0, 2, 4]]a[1:3, 2:4]np.where(a > 5, a, 0)Shape Manipulation 8
a.shapea.reshape(2, 3)a.flatten()a.Tnp.concatenate([a, b], axis=0)np.vstack([a, b])np.hstack([a, b])np.split(a, 3)Math & Statistics 10
a.sum()a.mean()a.std()a.min() / a.max()a.argmin() / a.argmax()a.cumsum()np.dot(a, b)a @ bnp.sort(a)np.unique(a)Broadcasting & Saving 7
a + 1a * 2a + b (compatible shapes)np.save("data.npy", a)np.load("data.npy")np.savetxt("data.csv", a, delimiter=",")np.loadtxt("data.csv", delimiter=",")Tips
- NumPy arrays are homogeneous - all elements share one dtype; mixing types is auto-promoted.
- Broadcasting rule: compare dimensions from the rightmost; they must be equal or one of them is 1.
- a * b is element-wise; use a @ b or np.dot(a, b) for matrix multiplication.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us