NdArray::triu

Construct a triangle matrix based on the upper triangle of another one.

Description

SciPhp\NdArray NdArray::triu( [ int $k = 0 ])

Parameters

$k
Default value is 0. It's an offset.

Return Values

A SciPhp\NdArray

Examples

Example #1: Extract upper triangle with no offset

use SciPhp\NumPhp as np;

$m np::ar(
  [[
123],
   [
456],
   [
789]]
)->
triu();

echo 
"m\n$m";

The above example will output:

m
[[1  2  3]
 [0  5  6]
 [0  0  9]]

Example #2: Extract upper triangle with offset 1

use SciPhp\NumPhp as np;

$m np::ar(
  [[
123],
   [
456],
   [
789]]
)->
triu(1);

echo 
"m\n$m";

The above example will output:

m
[[0  2  3]
 [0  0  6]
 [0  0  0]]

See Also

  • NumPhp::tri() - Construct an array with ones at and below the given diagonal and zeros elsewhere.
  • NdArray::tril() - Construct a triangle matrix based on the lower triangle of another one.
  • NdArray::vander() - Generate a Vandermonde matrix.