NumPhp::subtract

Subtract two matrices element-wise.

Description

SciPhp\NdArray NumPhp::subtract( 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: Subtract 2 square matrices

use SciPhp\NumPhp as np;

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

$s np::subtract($m$n);

echo 
"m=n\n$m""s=m-n\n$s";

The above example will output:

m=n
[[1  2  3]
 [4  5  6]
 [7  8  9]]
s=m-n
[[0  0  0]
 [0  0  0]
 [0  0  0]]

Example #2: Subtracting a vector and a matrix

use SciPhp\NumPhp as np;

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

$s np::subtract($m$n);

echo 
"m\n$m""n\n$n""s=m-n\n$s";

The above example will output:

m
[[1  2  3]
 [4  5  6]]
n
[1  2  3]
s=m-n
[[0  0  0]
 [3  3  3]]

Example #3: Addition of lambda and matrix

use SciPhp\NumPhp as np;

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

$s np::subtract($m3);

echo 
"m\n$m""s=m-3\n$s";

The above example will output:

m
[[1  2  3]
 [4  5  6]]
s=m-3
[[-2  -1  0 ]
 [1   2   3 ]]

See Also