Sidechair

matrix.columns()

Browse the reference

Returns how many values each row of a matrix holds, which is the width of the matrix.

Try it in the editor

matrix.columns(id) returns the width of a matrix: how many values sit in every row. All rows share one width, so it is also the size of any array that matrix.row returns.

Only matrix.add_col and matrix.remove_col change it. It matters before matrix.mult, which multiplies two matrices only when the left one has as many columns as the right one has rows.

Syntax

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

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to count columns in.

Returns

series int: The column count.

Example

Pine ScriptCheck shapes before multiplyingOpen in editor
//@version=6
indicator("matrix.columns: shape check", overlay = false)
matrix<float> a = matrix.new<float>(2, 3, 1.0)
matrix<float> b = matrix.new<float>(3, 2, 1.0)
fits = matrix.columns(a) == matrix.rows(b)
plot(fits ? matrix.rows(matrix.mult(a, b)) : na, "Product rows")

See also

Runs on Sidechair