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 axis specified by axis and where \(n\) is the axis 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.

  • axis (int) – axis 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 perform the operation by counting backward from the last axis (where -1 refers to the last axis). 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 N-1 axes, where N is number of axes in the shape determined according to Broadcasting along the non-contracted axes. The returned array must have a data type determined by Type Promotion Rules.

Raises:

Exception – an exception should be raised in the following circumstances: - if the size of the axis over which to compute the dot product is not the same (before broadcasting) for both x1 and x2.

Notes

  • The contracted axis must not be broadcasted.

Changed in version 2022.12: Added complex data type support.

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