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 dimension specified by
axisand 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
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.Note
The contracted axis (dimension) must not be broadcasted.
axis (int) – the axis (dimension) 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 compute the dot product by counting backward from the last dimension (where-1refers to the last dimension). 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 having rankN-1, whereNis 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
x1andx2.
Changed in version 2022.12: Added complex data type support.
Changed in version 2023.12: Restricted
axisto only negative integers.