๐Ÿ“˜ Lesson 2 of 6 ยท Computational Mathematics

๐Ÿ”ข NumPy

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.

Course progress: 33%

01 Key Concepts

The NumPy Array

NumPy's ndarray is like a Python list but far faster for math, supporting element-wise operations directly (no loops needed).

Creating Arrays

np.array([1,2,3]) creates a 1D array; np.array([[1,2],[3,4]]) creates a 2D array (matrix).

Element-wise Operations

Operations like array1 + array2 or array * 2 apply automatically to every element, unlike plain Python lists.

Useful Array Functions

np.mean(), np.sum(), np.max(), np.min(), and np.std() compute common statistics directly on an array.

Matrix Operations

NumPy supports matrix multiplication with np.dot() or the @ operator, plus np.linalg functions for determinants, inverses, and eigenvalues.

02 Key Formulas

03 Solved Examples

Example 1 Given arr = np.array([2,4,6,8]), what does np.mean(arr) return?
  1. Sum the elements: 2+4+6+8=20.
  2. Divide by the count: 20/4.
Answer: 5.0
Example 2 Given arr = np.array([1,2,3]), what does arr * 2 return?
  1. NumPy applies the multiplication to every element.
  2. 1*2=2, 2*2=4, 3*2=6.
Answer: array([2, 4, 6])
Example 3 Given a = np.array([1,2]) and b = np.array([3,4]), what does a + b return?
  1. Element-wise addition: 1+3=4, 2+4=6.
Answer: array([4, 6])

04 Practice Questions

1Given arr=np.array([5,10,15]), what does np.sum(arr) return?
30
2Given arr=np.array([1,2,3,4]), what does np.max(arr) return?
4
3What does np.array([1,2,3]) + 1 return?
array([2, 3, 4])
4What NumPy submodule handles linear algebra functions like determinants?
np.linalg
5What does the @ operator do between two NumPy arrays?
Performs matrix multiplication

๐Ÿ“„ NumPy โ€” Downloadable Worksheet

10 questions with a full answer key. Grab the PDF to print, or try the interactive version in your browser.