Week 4 glossary#
Online resources#
The official numpy documentations can be found at https://numpy.org/doc/stable/reference/index.html#reference. You may find the page of array creation routines (https://numpy.org/doc/stable/reference/routines.array-creation.html) and mathematical functions (https://numpy.org/doc/stable/reference/routines.math.html) especially useful.
Numpy syntax#
arithmetic#
+,-,*,/,//,%,**: vectorized arithmetic operators between 2 numpy arrays or between a numpy array and a scalar.
logical comparison#
==,!=,<,>,<=,>=: vectorized comparison operators between 2 numpy arrays or between a numpy array and a scalar.~: vectorized negation on a numpy boolean array&,|: vectorized “and” and “or” between two numpy boolean arrays
Array indexing#
[]: indexing operator on numpy arrays:: create basic slicing of the form start:stop:step
Numpy constants#
np.e: the natural / Euler / exponential numbernp.pi: the number \(\pi\)np.nan: the “not a number” value
Numpy array attributes#
<ndarray>.size: the size (number of entries) of a numpy array<ndarray>.shape: the shape of a numpy array<ndarray>.ndim: number of dimensions of the numpy array
Numpy functions#
Array creation#
np.array(): create an array from a python listnp.linspace(): create a linearly-spaced array of \(n\) elements from \(a\) to \(b\) (\(b\) inclusive)np.arange(): create an evenly-spaced array from \(a\) to \(b\) (\(b\) exclusive) at steps of \(d\)np.zeros(): create an array of zerosnp.ones(): create an array of onesnp.full(): create a constant arraynp.concatenate(): concatenate two numpy arrays into one
Mapping functions#
np.sqrt(): square rootnp.exp(): exponentiationnp.log(): natural logarithmnp.log10(): base-10 logarithmnp.log2(): base-2 logrithmnp.sin(),np.cos(),np.tan(): trigonometric functionsnp.arcsin(),np.arccos(),np.arctan(): inverse trigonometric functionsnp.arctan2(): arctangent function accepting bothxandyas argumentsdeg2rad(),rad2deg(): conversion between radians and degreesnp.round(): round values to fixed decimal pointnp.floor(): round down to the nearest integernp.ceil(): round up to the nearest integernp.fabs(): absolute value
Reduction functions#
np.mean(): calculating averagenp.var(): calculating variancenp.std(): calculating standard deviationnp.median(): calculating mediannp.quantile(): calculating quantilesnp.prod(): product over elementsnp.sum(): sum over elementsnp.max(),np.min(): finding extremum value of an arraynp.argmax(),np.argmin(): finding the index at which the extremum is attainednp.nanmean(),np.nanmedian(),np.nanvar(),np.nanstd(),np.nanmin(),np.nanmax(),np.nansum(): “nan-omitted” variation of the respective functions without thenanin their names
Other functions#
np.sort(): sort an arraynp.argsort(): sort the index of an array by the corresponding values