Returns the rank of a matrix: how many of its rows or columns are independent of the others.
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
matrix.rank(id: any matrix type) -> series int
matrix.rank() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The 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
//@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