NumPhp::tril

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

Description

SciPhp\NdArray NumPhp::tril( 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 lower triangle with no offset

use SciPhp\NumPhp as np;

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

print 
np::tril($m);

The above example will output:

[[1  0  0]
 [4  5  0]
 [7  8  9]]

Example #2: Extract lower triangle with offset -1

use SciPhp\NumPhp as np;

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

print 
np::tril($m, -1);

The above example will output:

[[0  0  0]
 [4  0  0]
 [7  8  0]]

See Also

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