MCPcopy Create free account
hub / github.com/numpy/numpy / dot

Function dot

numpy/core/multiarray.py:742–831  ·  view source on GitHub ↗

dot(a, b, out=None) Dot product of two arrays. Specifically, - If both `a` and `b` are 1-D arrays, it is inner product of vectors (without complex conjugation). - If both `a` and `b` are 2-D arrays, it is matrix multiplication, but using :func:`matmul` or ``a @ b`` is

(a, b, out=None)

Source from the content-addressed store, hash-verified

740
741@array_function_from_c_func_and_dispatcher(_multiarray_umath.dot)
742def dot(a, b, out=None):
743 """
744 dot(a, b, out=None)
745
746 Dot product of two arrays. Specifically,
747
748 - If both `a` and `b` are 1-D arrays, it is inner product of vectors
749 (without complex conjugation).
750
751 - If both `a` and `b` are 2-D arrays, it is matrix multiplication,
752 but using :func:`matmul` or ``a @ b`` is preferred.
753
754 - If either `a` or `b` is 0-D (scalar), it is equivalent to
755 :func:`multiply` and using ``numpy.multiply(a, b)`` or ``a * b`` is
756 preferred.
757
758 - If `a` is an N-D array and `b` is a 1-D array, it is a sum product over
759 the last axis of `a` and `b`.
760
761 - If `a` is an N-D array and `b` is an M-D array (where ``M>=2``), it is a
762 sum product over the last axis of `a` and the second-to-last axis of
763 `b`::
764
765 dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
766
767 It uses an optimized BLAS library when possible (see `numpy.linalg`).
768
769 Parameters
770 ----------
771 a : array_like
772 First argument.
773 b : array_like
774 Second argument.
775 out : ndarray, optional
776 Output argument. This must have the exact kind that would be returned
777 if it was not used. In particular, it must have the right type, must be
778 C-contiguous, and its dtype must be the dtype that would be returned
779 for `dot(a,b)`. This is a performance feature. Therefore, if these
780 conditions are not met, an exception is raised, instead of attempting
781 to be flexible.
782
783 Returns
784 -------
785 output : ndarray
786 Returns the dot product of `a` and `b`. If `a` and `b` are both
787 scalars or both 1-D arrays then a scalar is returned; otherwise
788 an array is returned.
789 If `out` is given, then it is returned.
790
791 Raises
792 ------
793 ValueError
794 If the last dimension of `a` is not the same size as
795 the second-to-last dimension of `b`.
796
797 See Also
798 --------
799 vdot : Complex-conjugating dot product.

Callers 5

test_dot_2argsMethod · 0.90
test_dot_3argsMethod · 0.90
tensordotFunction · 0.70
PyArray_MatrixProduct2Function · 0.50
_pyarray_correlateFunction · 0.50

Calls

no outgoing calls

Tested by 2

test_dot_2argsMethod · 0.72
test_dot_3argsMethod · 0.72