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])