import numpy as np★Universal alias — alwaysnp.np.__version__ np.show_config()Version / BLAS-LAPACK backend in use.np.pi np.e np.euler_gammaMath constants.np.inf np.nan np.newaxis★Infinity / not-a-number / axis-insertion token.np.iinfo(np.int32) np.finfo(np.float64)Integer / float type limits & precision.
np.array([1,2,3], dtype=np.float64)★Build from a list; set dtype explicitly.np.zeros((3,4)) np.ones((2,3)) np.full((2,2),7)★Filled arrays of a given shape.np.arange(0,10,2) np.linspace(0,1,5)★Ranges: fixed step / fixed count.np.eye(4) np.identity(3) np.diag(v)Identity / diagonal matrices.np.zeros_like(a) np.empty((2,2))Match another's shape / uninitialized (fast).np.fromfunction(f, (3,3)) np.meshgrid(x, y)★Build from a function / coordinate grids.
a.shape a.ndim a.size★Axis sizes / number of axes / total elements.a.dtype a.itemsize a.nbytes★Element type / bytes per item / total bytes.a.astype(np.float32)★Cast to a new dtype — returns a copy.a.T a.flags a.stridesTranspose / memory layout / byte strides.a.tolist() a.item(0)Back to Python list / scalar.
a[2] a[1, 3] a[1:4]★Element / 2D element / slice (0-indexed).a[:, 1] a[::-1]★Whole column / reverse an axis.a[start:stop:step]Full slice syntax, on any axis.a[..., 0]...(Ellipsis) fills in remaining axes.basic slices → viewsviewNo copy — the data is shared.
a[a > 5]★Elements matching a boolean condition.a[(a>2) & (a<9)]Combine masks with& | ~(notand/or).a[[0,2,4]] a[rows[:,None], cols]★Fancy indexing — pick by index arrays.np.where(cond, x, y)★Vectorized if/else, elementwise.np.take(a, idx) np.put(a, idx, vals)Gather / scatter by flat index.boolean / fancy → copycopyAlways returns new, independent memory.
np.nonzero(a) np.argwhere(a)★Indices of non-zero / True elements.np.select([c1,c2], [v1,v2], default=0)★Multi-condition vectorized choice.np.take_along_axis(a, idx, axis=1)Gather usingargsort/argmaxindices.np.ix_(rows, cols) np.indices((3,3))Open mesh for cross-indexing / index grids.np.diag_indices(3) np.tril / np.triuDiagonal / lower-upper triangle indices.np.fill_diagonal(a, 0)Write the diagonal in place.