Vector magnitude
Measure the magnitude of a vector for distance, residual, or convergence calculations.
SciPy · Class
Computes vector and matrix norms, choosing among norm definitions with ord. It also supports norms over selected axes and batched matrices.
scipy.linalg.norm selects a vector or matrix norm from the input shape and ord. With axis, it can compute norms across one axis or across batches of matrices; keepdims preserves reduced dimensions, and check_finite controls input validation for finite values.
scipy.linalg.norm(a, ord=None, axis=None, keepdims=False, check_finite=True)| Name | Type | Description |
|---|---|---|
a | array_like | Input array whose vector or matrix norm is calculated. |
ord | int, inf, -inf, 'fro', 'nuc', None, optional | Order of the norm; supported choices include integers, inf, -inf, 'fro', 'nuc', and None. |
axis | int, 2-tuple of ints, None, optional | Axis for vector norms, or a two-axis tuple for matrix norms; None selects behavior from input rank. |
keepdims | bool, optional | Whether reduced axes remain as dimensions of length one. |
check_finite | bool, optional | Whether to check that the input contains only finite values. |
nfloat or ndarray: Norm of the matrix or vector(s).
ord.axis produces vector norms along that dimension.ord=None for tensors beyond matrices and vectors.axis, the input dimensionality determines whether SciPy computes a vector or matrix norm.np.inf or -np.inf for infinite-order norms rather than string representations.import numpy as np
from scipy.linalg import norm
x = np.array([3.0, 4.0])
A = np.array([[1.0, 2.0], [3.0, 4.0]])
print(norm(x))
print(norm(A, ord="fro"))
print(norm(A, axis=1))Computes a vector 2-norm, a matrix Frobenius norm, and row-wise vector norms.
Measure the magnitude of a vector for distance, residual, or convergence calculations.
Quantify matrix size using Frobenius, induced, nuclear, or other matrix norms.
Calculate row, column, or batched-matrix norms without writing reduction loops.
scipy.linalg.norm compute, and how does ord affect it?It computes a matrix or vector norm. The selected definition depends on ord; the function supports eight matrix norms and infinitely many vector norms. For rank other than one or two, only ord=None is supported.
Follow-up: How do you compute norms over batches? Use axis as an integer for vector norms or a two-element tuple for matrix norms.
axis change the operation?An integer axis identifies the dimension along which vector norms are computed. A two-tuple identifies the two dimensions containing matrices, so matrix norms are computed over those dimensions.
Follow-up: What happens when axis=None? A one-dimensional input produces a vector norm, while a two-dimensional input produces a matrix norm.
keepdims and check_finite?keepdims=True retains reduced dimensions with length one, which helps the result broadcast against the original array. The result is a scalar or an array depending on the input and axes.
Follow-up: Why might check_finite=False be used? It can avoid finite-value checking, but inputs containing invalid values may then reach the underlying computation.
scipy.linalg.svdvalsnumpy.linalg.normscipy.linalg.det