Returns the upper triangle of a matrix.
TRIU(a, d)
a |
- |
A matrix. |
d |
- |
Optional. An integer, the diagonal on and above which to include matrix elements. Defaults to 0, the main diagonal. |
An array consisting of the upper triangle of a where the other elements are zero.
W1: {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}}
W2: triu(W1)
W2 == {{1, 2, 3},
{0, 5, 6},
{0, 0, 9}}
W3: triu(W1, 1)
W3 == {{0, 2, 3},
{0, 0, 6},
{0, 0, 0}}
W4: triu(W1, -1)
W4 == {{1, 2, 3},
{4, 5, 6},
{0, 8, 9}}
TRIU(a, 1) is equivalent to UPTRIX(a).
See TRIL to return the lower matrix.