Skip to main content

NDArray::dot

public static function dot(NDArray|array|float|int $a, NDArray|array|float|int $b): NDArray;

The dot function performs the dot product of two arrays. The behaviour of the function varies depending on the dimensions and shapes of the input arrays:

  • If both $a and $b are 1-D arrays, the dot product is computed as the inner product of the vectors.
  • If both $a and $b are 2-D arrays, the dot product is computed as the matrix multiplication (See NDArray::matmul).
  • If either $a or $b is a 0-D (scalar) array, the dot product is equivalent to element-wise multiplication. (See NDArray::multiply).
  • If $a is an N-D array and $b is a 1-D array, the dot product is computed as the sum product over the last axis of $a and $b.

Parameters

$a $b

Type NDArray|array|long|double

  • The arrays to perfom the dot product.

Return

Type - NDArray

  • If both $a and $b are scalars or 1-D arrays, the dot product operation yields a scalar value. In this case, a single scalar is returned as the result.
  • If either $a or $b is a scalar and the other is an array, or if both $a and $b are arrays with any dimensionality greater than 1, the dot product operation results in an array. The returned array will have a shape determined by the dimensions of $a and $b according to the dot product rules.

Notes

tip

GPU SUPPORTED

This operation is supported by GPU (VRAM) and contains a custom CUDA kernel.


Examples

use \NDArray as nd;

$a = nd::array([[1, 2],[3, 4]]);
$b = nd::array([1, 2]);

$result = nd::dot($a, $b);
print_r($result);
[5, 11]