Skip to main content

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

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]]