NDArray::add
public static function add(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray|float|int;
Add arguments element-wise
Parameters
$a
$b
- Type - NDArray | array | scalar
- The arrays to be added,
$a
and$b
must be of the same shape.
Return
NDArray
- The sum of
$a
and$b
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([[2, -2], [1, -1]]);
$b = new nd([[3, -3], [2, -1]]);
$c = $a + $b;
print_r($c);
[[5, -5],
[3, -2]]
use \NDArray as nd;
$a = new nd([[2, -2], [1, -1]]);
$b = new nd([[3, -3], [2, -1]]);
$c = nd::add($a, $b);
print_r($c);
[[5, -5],
[3, -2]]
use \NDArray as nd;
$c = nd::add([5, 2, -3], [4, 3, 2]);
print_r($c);
[9, 5, -1]