Sidechair

matrix.rank()

Browse the reference

Returns the rank of a matrix: how many of its rows or columns are independent of the others.

Try it in the editor

A full-rank square matrix has rank equal to its size and is invertible. A lower rank means some rows are combinations of the others.

[[1, 2], [2, 4]] has rank 1 because its second row is twice its first, while [[1, 0], [0, 1]] has rank 2. A matrix of all zeros has rank 0. The rank works for any shape and cannot exceed the smaller of the row and column counts.

Syntax

Pine Script
matrix.rank(id: any matrix type) -> series int
matrix.rank() -> series int

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix whose independent rows are counted; any number of rows and columns is accepted.

Returns

  • series int: The rank as a whole number from 0 up to the smaller of the row and column counts.
  • series int: The rank of the receiving matrix as a whole number.

Example

Pine ScriptDetect dependent rowsOpen in editor
//@version=6
indicator("matrix.rank: independence", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 1.0)
plot(matrix.rank(m), "Rank")

See also

Runs on Sidechair