Appendix B — NumPy arrays

This appendix provides a quick-reference guide to the main NumPy array tools used in this book. We focus on functions, methods, and attributes used directly with NumPy arrays or used to create arrays for numerical work. To keep the list compact, we omit random-number-generator methods (for example, rng.normal()) and constants or dtypes such as np.nan or np.int8.

Table B.1: Common NumPy functions used with arrays
Function Purpose Where used
np.array() Build an array from a sequence
np.arange() Integer sequence
np.asarray() Convert to an array
np.empty() Uninitialized array
np.full() Fill with one value
np.zeros() Zeros array
np.ones() Ones array
np.repeat() Repeat values
np.tile() Repeat blocks
np.linspace() Evenly spaced values
np.column_stack() Bind columns into a matrix
np.c_[] Column-bind using index syntax
np.sum() Sum values
np.mean() Mean
np.std() Standard deviation
np.median() Median
np.quantile() Quantile or cutoff
np.cov() Covariance matrix
np.sqrt() Square root
np.exp() Exponential
np.abs() Absolute value
np.where() Conditional choice
np.minimum() Elementwise minimum
np.argmax() Index of maximum
np.diag() Diagonal of a matrix
np.outer() Outer product
np.fill_diagonal() Fill matrix diagonal
Table B.2: Common NumPy array methods
Method Purpose Where used
.sum() Sum values
.mean() Mean
.max() Maximum
.min() Minimum
.astype() Convert dtype
.item() Extract a scalar
Table B.3: Common NumPy array attributes
Attribute Purpose Where used
.dtype Stored data type
.size Number of elements
.shape Array dimensions
.T Matrix transpose