NdArray::dot

Dot product of two matrices.

Description

SciPhp\NdArray NdArray::dot( array|NdArray $n )

Parameters

$n
An array [1, 2, 3] or a NdArray.

Return Values

The new SciPhp\NdArray

Examples

Example #1: Product of 2 square matrices

use SciPhp\NumPhp as np;

$m np::linspace(199)->reshape(33);
$n np::linspace(199)->reshape(33);

$p $m->dot($n);

echo 
"m=n\n$m""p=m.n\n$p";

The above example will output:

m=n
[[1  2  3]
 [4  5  6]
 [7  8  9]]
p=m.n
[[30   36   42 ]
 [66   81   96 ]
 [102  126  150]]

Example #2: Product of non square matrices

use SciPhp\NumPhp as np;

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

$p $m->dot($n);

echo 
"m\n$m""n\n$n""p=m.n\n$p";

The above example will output:

m
[[1  2  3]
 [4  5  6]]
n
[[1   2   3   4 ]
 [5   6   7   8 ]
 [9   10  11  12]]
p=m.n
[[38   44   50   56 ]
 [83   98   113  128]]

Example #3: Product lambda . matrix

use SciPhp\NumPhp as np;

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

$p $m->dot(5);

echo 
"m\n$m""p=m.5\n$p";

The above example will output:

m
[[1  2  3]
 [4  5  6]]
p=m.5
[[5   10  15]
 [20  25  30]]

See Also