NumPhp::triu

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

Description

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

Parameters

$matrix
SciPhp\NdArray  Initial matrix.
$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]]
);

print 
np::triu($m);

The above example will output:

[[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]]
);

print 
np::triu($m1);

The above example will output:

[[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.
  • NumPhp::tril() - Construct a triangle matrix based on the lower triangle of another one.
  • NumPhp::vander() - Generate a Vandermonde matrix.