vecdot

vecdot(x1: array, x2: array, /, *, axis: int = -1) array

Computes the (vector) dot product of two arrays.

Let \(\mathbf{a}\) be a vector in x1 and \(\mathbf{b}\) be a corresponding vector in x2. The dot product is defined as

\[\mathbf{a} \cdot \mathbf{b} = \sum_{i=0}^{n-1} \overline{a_i}b_i\]

over the dimension specified by axis and where \(n\) is the dimension size and \(\overline{a_i}\) denotes the complex conjugate if \(a_i\) is complex and the identity if \(a_i\) is real-valued.

Parameters:
  • x1 (array) – first input array. Should have a floating-point data type.

  • x2 (array) –

    second input array. Must be compatible with x1 for all non-contracted axes (see Broadcasting). The size of the axis over which to compute the dot product must be the same size as the respective axis in x1. Should have a floating-point data type.

    Note

    The contracted axis (dimension) must not be broadcasted.

  • axis (int) – the axis (dimension) of x1 and x2 containing the vectors for which to compute the dot product. Should be an integer on the interval [-N, -1], where N is min(x1.ndim, x2.ndim). The function must determine the axis along which to compute the dot product by counting backward from the last dimension (where -1 refers to the last dimension). By default, the function must compute the dot product over the last axis. Default: -1.

Returns:

out (array) – if x1 and x2 are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and having rank N-1, where N is the rank (number of dimensions) of the shape determined according to Broadcasting along the non-contracted axes. The returned array must have a data type determined by Type Promotion Rules.

Notes

Raises

  • if the size of the axis over which to compute the dot product is not the same (before broadcasting) for both x1 and x2.

Changed in version 2022.12: Added complex data type support.

Changed in version 2023.12: Restricted axis to only negative integers.