Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Class

norm

Computes vector and matrix norms, choosing among norm definitions with ord. It also supports norms over selected axes and batched matrices.

How it works

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.

Syntax

scipy.linalg.norm(a, ord=None, axis=None, keepdims=False, check_finite=True)

Parameters

NameTypeDescription
aarray_likeInput array whose vector or matrix norm is calculated.
ordint, inf, -inf, 'fro', 'nuc', None, optionalOrder of the norm; supported choices include integers, inf, -inf, 'fro', 'nuc', and None.
axisint, 2-tuple of ints, None, optionalAxis for vector norms, or a two-axis tuple for matrix norms; None selects behavior from input rank.
keepdimsbool, optionalWhether reduced axes remain as dimensions of length one.
check_finitebool, optionalWhether to check that the input contains only finite values.

Returns

nfloat or ndarray: Norm of the matrix or vector(s).

Key points

  • The function handles both vector and matrix norm calculations.
  • Matrix inputs support eight norm definitions selected through ord.
  • Vector inputs can use any supported real-valued order, including infinite orders.
  • An integer axis produces vector norms along that dimension.
  • A two-axis tuple lets the function evaluate matrix norms across batched matrices.
  • The return is a scalar or ndarray containing the requested norm value or values.

Common mistakes

  • Higher-rank inputs cannot use a specified norm order; use ord=None for tensors beyond matrices and vectors.
  • Without axis, the input dimensionality determines whether SciPy computes a vector or matrix norm.
  • Pass NumPy's np.inf or -np.inf for infinite-order norms rather than string representations.

Example: Compute vector and matrix norms

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.

When to use it

Vector magnitude

Measure the magnitude of a vector for distance, residual, or convergence calculations.

Matrix analysis

Quantify matrix size using Frobenius, induced, nuclear, or other matrix norms.

Axis-wise and batched reductions

Calculate row, column, or batched-matrix norms without writing reduction loops.

Interview questions

QWhat does 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.

QHow does 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.

QWhat are the roles of 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.svdvals
  • numpy.linalg.norm
  • scipy.linalg.det

Source: Norm. Checked 2026-10-15.