NDArray::subtract
public static function subtract(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray|float|int;
Subtract two arrays element-wise
Parameters
$a
$b
- Type - NDArray | array | scalar
- Input arrays
Return
NDArray
- Element-wise subtraction of
$a
and$b
element-wise
Notes
tip
GPU SUPPORTED
This operation is supported by GPU (VRAM) and contains a custom CUDA kernel.
Examples
- Example 1
- Example 2
- Example 3
use \NDArray as nd;
$a = new nd([[1, 2], [3, 4]]);
$b = new nd([[1, 2], [3, 4]]);
$c = nd::subtract($a, $b);
print_r($c);
[[0, 0],
[0, 0]]
use \NDArray as nd;
$c = nd::subtract([1, 2, 3], [10, 10, 10]);
print_r($c);
[-9, -8, -7]
use \NDArray as nd;
$a = new nd([[1, 2], [3, 4]]);
$b = new nd([[1, 2], [3, 4]]);
$c = $a - $b;
print_r($c);
[[0, 0],
[0, 0]]