Exchanges two rows of a matrix in place.
The items of the two rows trade places and every other row stays where it is. Swapping a row with itself changes nothing.
Row operations such as pivoting in elimination are built from swaps like this.
Syntax
matrix.swap_rows(id: any matrix type, row1: series int, row2: series int) -> void
matrix.swap_rows(row1: series int, row2: series int) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix whose two rows trade places in place. |
| row1 | series int | required | Index of the first row to swap. Counts from 0. |
| row2 | series int | required | Index of the second row to swap. Counts from 0. |
Returns
Nothing.
Example
//@version=6
indicator("matrix.swap_rows: swap", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 0.0)
matrix.set(m, 0, 0, 1.0)
matrix.set(m, 1, 0, 2.0)
matrix.swap_rows(m, 0, 1)
plot(matrix.get(m, 0, 0), "Now 2")See also
Runs on Sidechair