composer require sciphp/numphp
require "vendor/autoload.php";
use SciPhp\NumPhp as np;
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]]
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]]
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]]
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]]