Sidechair

matrix.transpose()

Browse the reference

Returns a new matrix where rows and columns are swapped.

Try it in the editor

An r by c matrix becomes c by r, with item (i, j) of the original at position (j, i). The original is left unchanged.

Transposing is the first step in many products, such as the normal equations of a regression.

Syntax

Pine Script
matrix.transpose(id: any matrix type) -> matrix<>
matrix.transpose() -> matrix<>

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to flip over its main diagonal. The result is a new matrix.

Returns

matrix<>: A new matrix, the transpose of the original.

Example

Pine ScriptRows become columnsOpen in editor
//@version=6
indicator("matrix.transpose: flip", overlay = false)
matrix<float> m = matrix.new<float>(2, 3, 1.0)
t = matrix.transpose(m)
plot(matrix.rows(t), "Rows after transpose")

See also

Runs on Sidechair