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
x1and \(\mathbf{b}\) be a corresponding vector inx2. 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
axisand 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
x1for 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 inx1. Should have a floating-point data type.axis (int) – axis of
x1andx2containing the vectors for which to compute the dot product. Should be an integer on the interval[-N, -1], whereNismin(x1.ndim, x2.ndim). The function must determine the axis along which to perform the operation by counting backward from the last axis (where-1refers to the last axis). By default, the function must compute the dot product over the last axis. Default:-1.
- Returns:
out (array) – if
x1andx2are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and havingN-1axes, whereNis 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
x1andx2.
Notes
The contracted axis must not be broadcasted.
Changed in version 2022.12: Added complex data type support.
Changed in version 2023.12: Restricted
axisto only negative integers.