Returns how many values each row of a matrix holds, which is the width of the matrix.
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
matrix.columns(id: any matrix type) -> series int
matrix.columns() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix to count columns in. |
Returns
series int: The column count.
Example
//@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