Tutorial

Quick install

composer require sciphp/numphp

In a PHP file

require "vendor/autoload.php";

use 
SciPhp\NumPhp as np;

First matrix

Construct a matrix 3*3

use SciPhp\NumPhp as np;

$m = np::linspace(1, 9, 9)->reshape(3, 3);

print 
"m\n$m";
m
[[1  2  3]
 [4  5  6]
 [7  8  9]]

Addition

use SciPhp\NumPhp as np;

$m = np::linspace(1, 6, 6)->reshape(2, 3);

$a = np::add($m, 6);

echo 
"m\n$m", "a=m+6\n$a";
m
[[1  2  3]
 [4  5  6]]
a=m+6
[[7   8   9 ]
 [10  11  12]]

Dot matrices

use SciPhp\NumPhp as np;

// Construct 2 matrices 3*3
$m = np::vander([1, 2, 3]);
$n = np::linspace(1, 9, 9)->reshape(3, 3);

$a = np::dot($m, $n);

echo 
"m\n$m", "n\n$n", "a=m.n\n$a";
m
[[1  1  1]
 [4  2  1]
 [9  3  1]]
n
[[1  2  3]
 [4  5  6]
 [7  8  9]]
a=m.n
[[12  15  18]
 [19  26  33]
 [28  41  54]]

Chaining actions

use SciPhp\NumPhp as np;

$triangle = np::vander([1, 2, 4])->reciprocal()->resize(4, 4)->tril();

echo 
"triangle\n$triangle";
triangle
[[1       0       0       0     ]
 [0.5     1       0       0     ]
 [1       1       1       0     ]
 [0.25    0.5     1       0.0625]]

See Also