Changes the number of rows and columns of a matrix without changing its items.
The items are read row by row and laid out again in the new shape, so a 2 by 3 matrix can become 3 by 2 or 1 by 6. The new row count times the column count has to equal the element count.
Unlike matrix.transpose(), it keeps the reading order of the items rather than swapping rows and columns.
Syntax
matrix.reshape(id: any matrix type, rows: series int, columns: series int) -> void
matrix.reshape(rows: series int, columns: series int) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix to give a new shape. The items keep their row-by-row order. |
| rows | series int | required | Number of rows after the change. Rows times columns must equal the item count. |
| columns | series int | required | Number of columns after the change. Rows times columns must equal the item count. |
Returns
Nothing.
Example
//@version=6
indicator("matrix.reshape: flatten", overlay = false)
matrix<float> m = matrix.new<float>(2, 3, 1.0)
matrix.reshape(m, 1, 6)
plot(matrix.columns(m), "Columns now")See also
Runs on Sidechair