numpynotes.
md 2025-05-16
Nice! Since you’re diving into a full NumPy course, here’s a structured note in Markdown format (can be
converted to HTML, LaTeX, or PDF later if you want). It's beginner-friendly, organized, and useful as a cheat
sheet or study guide:
📊 NumPy Full Course Notes
🔧 What is NumPy?
NumPy is a Python library used for scientific computing.
Fundamental for many other libraries like pandas, scikit-learn, and TensorFlow.
Works with multi-dimensional arrays and provides powerful methods to operate on them.
⚡ Why Use NumPy Over Lists?
Feature Python Lists NumPy Arrays
Speed Slower Much faster
Memory Uses more memory Uses less memory
Type-checking Dynamic Fixed (int32, float64, etc.)
Memory layout Scattered Contiguous
NumPy arrays allow vectorized operations, utilize SIMD and cache better.
🛠 Array Initialization
import numpy as np
# 1D Array
a = np.array([1, 2, 3])
# 2D Array
b = np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]])
# Zeros, Ones, Full
np.zeros((2, 3))
np.ones((3, 3), dtype='int32')
np.full((2, 2), 99)
# Identity Matrix
np.identity(3)
# Random Arrays
np.random.rand(4, 2) # Random floats (0 to 1)
np.random.randint(0, 10, (3, 3)) # Random integers
1/4
numpynotes.md 2025-05-16
🔍 Array Properties
a.shape # (3,)
a.ndim # 1
a.dtype # int32, float64, etc.
a.size # Number of elements
a.itemsize # Bytes per element
a.nbytes # Total bytes
🔄 Reshape, Copy & Repeat
a.reshape(2, 3) # Change shape
np.repeat(a, 3, axis=0) # Repeat elements
a.copy() # Deep copy to avoid pointer issues
🔢 Indexing & Slicing
a[0, 1] # Element at row 0, column 1
a[:, 2] # All rows, column 2
a[1, 1:-1:2] # Fancy slicing
a[1:3, 2:5] # Submatrix
➕ Math Operations
a + 10
a * 2
a ** 2
np.sin(a)
np.sqrt(a)
🧮 Linear Algebra
a @ b # Matrix multiplication
np.matmul(a, b)
np.linalg.det(a) # Determinant
2/4
numpynotes.md 2025-05-16
np.linalg.inv(a) # Inverse
np.linalg.eig(a) # Eigenvalues
📊 Statistics
np.min(a)
np.max(a)
np.mean(a)
np.sum(a)
np.std(a)
np.var(a)
Use axis=0 for columns, axis=1 for rows.
📂 Load from File
data = np.genfromtxt("data.txt", delimiter=',')
data = data.astype(np.int32) # Convert type
🧠 Advanced Indexing
mask = a > 50
a[mask] # Filtered values
# Combining Conditions
a[(a > 50) & (a < 100)]
# Index with list
a[[0, 2, 4]]
📦 Stacking & Reorganizing
np.vstack([a, b]) # Vertical stack
np.hstack([a, b]) # Horizontal stack
🧪 Quizzes (Practice Time!)
Try slicing:
3/4
numpynotes.md 2025-05-16
Get submatrix: rows 1 to 2, columns 0 to 1
Select odd-indexed rows
Reverse columns using slicing
If you'd like this converted to HTML, LaTeX, or a downloadable PDF, just say the word and I’ll prep it! Also, we
can turn these into flashcards, mini-projects, or quizzes if you want to test your knowledge. Up for it? 😊
4/4