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

SciPy · Function

linalg.expm

Computes the matrix exponential of a square array, including arrays with leading batch dimensions. It uses a variable-order Padé approximation and returns an array shaped like the input.

How it works

Pass a square NumPy array, or an array with batch dimensions followed by two equal dimensions. SciPy evaluates the matrix exponential using a variable-order Padé approximation selected from the input data and returns an array with the same shape.

Syntax

scipy.linalg.expm(A)

Parameters

NameTypeDescription
AndarrayInput array whose final two dimensions are square; optional leading dimensions represent batches.

Returns

ndarray: The matrix exponential, with the same shape as A.

Key points

  • The function computes the matrix exponential for an input array.
  • The final two axes must form an n-by-n square matrix; preceding axes may represent batches.
  • Leading dimensions are processed as independent matrix slices.
  • The output retains the input array's shape.
  • SciPy uses a data-dependent, variable-order Padé approximation.

Common mistakes

  • Budget memory for large matrices: the documented worst-case usage grows on the order of 8n².
  • Unsupported numeric dtypes may trigger an internal copy, which can increase memory use.
  • For dimensions of at least 400, SciPy switches from exact 1-norm evaluation to estimation when choosing the approximation order.

Example: Matrix exponential

import numpy as np
from scipy.linalg import expm

A = np.array([[0.0, 1.0], [-1.0, 0.0]])
print(expm(A))

Computes the exponential of a two-dimensional rotation generator.

When to use it

Linear dynamical systems

Convert a continuous-time linear system matrix into a finite-time state-transition matrix.

Matrix-function evaluation

Evaluate matrix-valued exponentials for rotations, diffusion, or other linear operators.

Batched computation

Apply the same matrix-exponential operation independently across several matrices stored in one array.

Interview questions

QWhat algorithm does scipy.linalg.expm use?

expm(A) computes the matrix exponential of a square array. The implementation uses a variable-order Padé approximation whose order is chosen from the array data.

Follow-up: What happens with batched input? Arrays whose final two dimensions are square are interpreted as batches of lower-dimensional matrices, and the output preserves the complete shape.

QWhat input and output shapes are supported?

The input must have square last two dimensions, with shape (..., n, n). The result is an array with the same shape as the input.

Follow-up: Why might the result require extra memory? The implementation can use worst-case memory on the order of 8*(n**2) for an n-by-n input.

QHow does matrix size affect order selection?

For dimensions at least 400, the method uses 1-norm estimation to help determine the approximation order because its cost becomes preferable to exact computation. The threshold is based on the matrix dimension n.

Follow-up: What dtype-related allocation should be considered? Inputs outside single or double precision real or complex dtypes are copied into a new array.

  • scipy.linalg.logm
  • scipy.linalg.sinm
  • scipy.linalg.cosm
  • scipy.linalg.solve

Source: expm — SciPy v1.17.0 Manual. Checked 2026-10-15.