NdArray::tril

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

Description

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

Parameters

$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]]
)->
tril();

echo 
"m\n$m";

The above example will output:

m
[[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]]
)->
tril(-1);

echo 
"m\n$m";

The above example will output:

m
[[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.
  • NdArray::triu() - Construct a triangle matrix based on the upper triangle of another one.
  • NdArray::vander() - Generate a Vandermonde matrix.