Returns true when a matrix has as many rows as columns.
A matrix is square when its row count equals its column count: a 2 by 2 or 3 by 3 grid passes and a 2 by 3 grid does not.
Determinants, inverses, traces and eigenvalues only exist for square matrices, so this is the guard to run before calling them. Compare matrix.rows() with matrix.columns() when you need the two counts themselves.
Syntax
matrix.is_square(id: any matrix type) -> series bool
matrix.is_square() -> series boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix whose row count and column count are compared; it is only read, never changed. |
Returns
series bool: true when the rows and columns match in number, otherwise false.series bool: true when the receiving matrix has as many rows as columns, otherwise false.
Example
//@version=6
indicator("matrix.is_square: guard", overlay = false)
matrix<float> m = matrix.new<float>(2, 3, 1.0)
plot(matrix.is_square(m) ? matrix.det(m) : na, "Determinant if square")See also
Runs on Sidechair