Skip to content

pymath.inverse

Daniel Flassig edited this page Jun 24, 2026 · 1 revision

Returns the inverse of a square matrix, or nil if the matrix is not invertible.

result = pymath.inverse(m)
Parameter Type Description
m matrix A square matrix (n × n), represented as an array of n row-vectors.

Return value

Type Description
result A new n × n matrix, the inverse of m, or nil if m is singular (not invertible).

Notes:

  • m must be square, otherwise an error is raised.

See pymath for details on how a matrix is represented in the PYTHA Lua API.

Example:

local A = {{4, 7},
           {2, 6}}
local Ainv = pymath.inverse(A)
-- Ainv == {{ 0.6, -0.7},
--          {-0.2,  0.4}}

local S = {{1, 2},
           {2, 4}}        -- singular
local Sinv = pymath.inverse(S)
-- Sinv == nil

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.dot, pymath.transpose

Clone this wiki locally