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(199)->reshape(33);

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

Addition

use SciPhp\NumPhp as np;

$m np::linspace(166)->reshape(23);

$a np::add($m6);

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([123]);
$n np::linspace(199)->reshape(33);

$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([124])->reciprocal()->resize(44)->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