📝 Worksheet← Lesson
BitWithBite
Computational Mathematics · Quick Reference

NumPy Cheat Sheet

Computational Mathematics · Lesson 2/6
In one line: numPy is Python's core library for numerical computing — it introduces the array, a fast, memory-efficient way to store and operate on large sets of numbers, especially for linear algebra and statistics.

Key Ideas

1The NumPy Array. NumPy's ndarray is like a Python list but far faster for math, supporting element-wise operations directly (no loops needed).
2Creating Arrays. np.array([1,2,3]) creates a 1D array; np.array([[1,2],[3,4]]) creates a 2D array (matrix).
3Element-wise Operations. Operations like array1 + array2 or array * 2 apply automatically to every element, unlike plain Python lists.
4Useful Array Functions. np.mean(), np.sum(), np.max(), np.min(), and np.std() compute common statistics directly on an array.
5Matrix Operations. NumPy supports matrix multiplication with np.dot() or the @ operator, plus np.linalg functions for determinants, inverses, and eigenvalues.

Worked Examples

Given arr = np.array([2,4,6,8]), what does np.mean(arr) return?
5.0
Given arr = np.array([1,2,3]), what does arr * 2 return?
array([2, 4, 6])
Given a = np.array([1,2]) and b = np.array([3,4]), what does a + b return?
array([4, 6])

Formulas

np.array([1,2,3]) creates a 1D array
np.mean(arr) computes the average
np.dot(A, B) or A @ B performs matrix multiplication

Practice Yourself

Given arr=np.array([5,10,15]), what does np.sum(arr) return?
30
Given arr=np.array([1,2,3,4]), what does np.max(arr) return?
4
What does np.array([1,2,3]) + 1 return?
array([2, 3, 4])