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

SciPy · Function

solve

Solves the square-matrix system a @ x = b. Structure hints, batching, transpose solving, overwrite options, and finite-value checking are supported.

How it works

solve computes x for the linear system a @ x = b. It accepts one matrix and either one or multiple right-hand sides, while optional structure hints such as assume_a="sym" select a specialized solver; batch dimensions may also precede the core matrix dimensions.

Syntax

scipy.linalg.solve(a, b, lower=False, overwrite_a=False, overwrite_b=False, check_finite=True, assume_a=None, transposed=False)

Parameters

NameTypeDescription
aarray_like, shape (…, N, N)Square left-hand-side matrix or a batch of matrices.
barray_like, shape (…, N, NRHS)Right-hand-side data or a batch of right-hand sides.
lowerbool, default: FalseWhether the referenced structured matrix uses its lower triangle; ignored for other structures.
overwrite_abool, default: FalsePermit overwriting a, potentially improving performance.
overwrite_bbool, default: FalsePermit overwriting b, potentially improving performance.
check_finitebool, default: TrueCheck that input matrices contain only finite values.
assume_astr, optionalKnown matrix structure, such as diagonal, tridiagonal, banded, sym, her, pos, or gen.
transposedbool, default: FalseSolve using the transpose of a.

Returns

x, an ndarray containing the solution, with shape (N, NRHS) or (…, N) depending on the right-hand side.

Key points

  • Use assume_a to select a solver specialized for known matrix structure.
  • Inputs can contain leading batch dimensions in addition to their core matrix dimensions.
  • The default finite-value validation protects against non-finite matrix entries.
  • overwrite_a=True permits reuse of the matrix storage and may improve performance.
  • Set transposed=True to solve against the transpose of a.

Common mistakes

  • Setting check_finite=False can improve speed, but invalid values may cause crashes or non-termination.
  • The lower option has no effect unless the selected matrix structure is symmetric, Hermitian, or positive definite.
  • transposed=True solves the ordinary transpose system, not the conjugate transpose system.

Example: Solve a symmetric linear system

import numpy as np
from scipy.linalg import solve

a = np.array([[3.0, 1.0], [1.0, 2.0]])
b = np.array([9.0, 8.0])
x = solve(a, b, assume_a="sym")
print(x)  # [2. 3.]

Solves a symmetric two-by-two system and prints the solution vector.

When to use it

Solve coupled linear equations

Numerical models and simulations

Process batched systems

Many independent systems with compatible leading dimensions

Use a structure-specific solver

Known symmetric, Hermitian, diagonal, banded, or triangular structure

Interview questions

QWhat problem does scipy.linalg.solve solve?

It finds x satisfying a @ x = b, where a must be square. The right-hand side can represent one or several systems.

Follow-up: How can performance improve for structured matrices? Pass the appropriate assume_a value, such as sym, her, pos, diagonal, or tridiagonal, so SciPy can choose a dedicated solver.

QWhat shapes do a, b, and the result support?

a is a square matrix or batch of square matrices. b contains the matching right-hand side vector or matrix, and the result has the corresponding solution shape.

Follow-up: What does batching mean here? Additional dimensions may precede the core (N, N) matrix shape, allowing multiple systems to be supplied together.

QWhat is the purpose and risk of check_finite?

check_finite=True verifies that input matrices contain only finite numbers. Disabling it can be faster, but bad values can lead to serious runtime problems.

Follow-up: When is disabling the check reasonable? Only when finiteness is guaranteed by trusted upstream validation and the performance trade-off is worthwhile.

  • scipy.linalg.solve_triangular
  • scipy.linalg.solve_banded
  • scipy.linalg.lstsq
  • scipy.linalg.inv

Source: Solve. Checked 2026-10-15.