NumPhp::multiply

Multiply two matrices, element-wise.

Description

SciPhp\NdArray NumPhp::multiply( array|NdArray $m , array|NdArray $n )

Parameters

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

Return Values

The new SciPhp\NdArray

Examples

Example #1: Multiply all elements by lambda

use SciPhp\NumPhp as np;

$m np::vander([123]);

$r np::multiply($m2);

echo 
"m\n$m""r=m*2\n$r";

The above example will output:

m
[[1  1  1]
 [4  2  1]
 [9  3  1]]
d=m*2
[[2   2   2 ]
 [8   4   2 ]
 [18  6   2 ]]

Example #2: Multiply two square matrices

use SciPhp\NumPhp as np;

$m np::arange(0182)->reshape(33);
$n np::vander([124]);

$r np::multiply($m$n);

echo 
"m\n$m""n\n$n""r=m*n\n$r";

The above example will output:

m
[[0   2   4 ]
 [6   8   10]
 [12  14  16]]
n
[[1   1   1 ]
 [4   2   1 ]
 [16  4   1 ]]
r=m*n
[[0    2    4  ]
 [24   16   10 ]
 [192  56   16 ]]

See Also