Skip to content

vecdot

Computes the (vector) dot product of two arrays.

Parameters:

Name Type Description Default
x1 array_like

Input sparse arrays

required
x2 array_like

Input sparse arrays

required
axis int

The axis to reduce over.

-1

Returns:

Name Type Description
out Union[SparseArray, ndarray]

Sparse or 0-D array containing dot product.

Source code in sparse/numba_backend/_common.py
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
def vecdot(x1, x2, /, *, axis=-1):
    """
    Computes the (vector) dot product of two arrays.

    Parameters
    ----------
    x1, x2 : array_like
        Input sparse arrays
    axis : int
        The axis to reduce over.

    Returns
    -------
    out : Union[SparseArray, numpy.ndarray]
        Sparse or 0-D array containing dot product.
    """
    ndmin = builtins.min((x1.ndim, x2.ndim))
    if not (-ndmin <= axis < ndmin) or x1.shape[axis] != x2.shape[axis]:
        raise ValueError("Shapes must match along `axis`.")

    if np.issubdtype(x1.dtype, np.complexfloating):
        x1 = np.conjugate(x1)

    return np.sum(x1 * x2, axis=axis, dtype=np.result_type(x1, x2))