NumPy Cheat Sheet
NumPy arrays, operations, broadcasting, and linear algebra essentials.
2 PagesIntermediateMay 4, 2026
Creating Arrays
Construct NumPy arrays.
python
import numpy as npa = np.array([1, 2, 3])zeros = np.zeros((2, 3))ones = np.ones((3, 3))range_arr = np.arange(0, 10, 2)lin = np.linspace(0, 1, 5)
Shape & Indexing
Inspect and slice arrays.
python
a.shape # (rows, cols)a.reshape(3, 2)a[0, :] # First rowa[:, 1] # Second columna[a > 2] # Boolean indexing
Vectorized Operations
Element-wise math without loops.
python
b = a * 2c = a + bd = np.sqrt(a)sum_all = a.sum()mean_val = a.mean()
Broadcasting
Operate on arrays of different shapes.
python
m = np.array([[1, 2], [3, 4]])v = np.array([10, 20])result = m + v # v is "broadcast" across each row
Pro Tip
Avoid Python for-loops over NumPy arrays — vectorized operations are implemented in C and are dramatically faster.
Was this cheat sheet helpful?
Explore Topics
#NumPy#NumPyCheatSheet#DataScience#Intermediate#CreatingArrays#ShapeIndexing#VectorizedOperations#Broadcasting#DataStructures#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance