MCPcopy Index your code
hub / github.com/numpy/numpy / multi_dot

Function multi_dot

numpy/linalg/_linalg.py:2865–2981  ·  view source on GitHub ↗

Compute the dot product of two or more arrays in a single function call, while automatically selecting the fastest evaluation order. `multi_dot` chains `numpy.dot` and uses optimal parenthesization of the matrices [1]_ [2]_. Depending on the shapes of the matrices, this can spe

(arrays, *, out=None)

Source from the content-addressed store, hash-verified

2863
2864@array_function_dispatch(_multidot_dispatcher)
2865def multi_dot(arrays, *, out=None):
2866 """
2867 Compute the dot product of two or more arrays in a single function call,
2868 while automatically selecting the fastest evaluation order.
2869
2870 `multi_dot` chains `numpy.dot` and uses optimal parenthesization
2871 of the matrices [1]_ [2]_. Depending on the shapes of the matrices,
2872 this can speed up the multiplication a lot.
2873
2874 If the first argument is 1-D it is treated as a row vector.
2875 If the last argument is 1-D it is treated as a column vector.
2876 The other arguments must be 2-D.
2877
2878 Think of `multi_dot` as::
2879
2880 def multi_dot(arrays): return functools.reduce(np.dot, arrays)
2881
2882
2883 Parameters
2884 ----------
2885 arrays : sequence of array_like
2886 If the first argument is 1-D it is treated as row vector.
2887 If the last argument is 1-D it is treated as column vector.
2888 The other arguments must be 2-D.
2889 out : ndarray, optional
2890 Output argument. This must have the exact kind that would be returned
2891 if it was not used. In particular, it must have the right type, must be
2892 C-contiguous, and its dtype must be the dtype that would be returned
2893 for `dot(a, b)`. This is a performance feature. Therefore, if these
2894 conditions are not met, an exception is raised, instead of attempting
2895 to be flexible.
2896
2897 Returns
2898 -------
2899 output : ndarray
2900 Returns the dot product of the supplied arrays.
2901
2902 See Also
2903 --------
2904 numpy.dot : dot multiplication with two arguments.
2905
2906 References
2907 ----------
2908
2909 .. [1] Cormen, "Introduction to Algorithms", Chapter 15.2, p. 370-378
2910 .. [2] https://en.wikipedia.org/wiki/Matrix_chain_multiplication
2911
2912 Examples
2913 --------
2914 `multi_dot` allows you to write::
2915
2916 >>> import numpy as np
2917 >>> from numpy.linalg import multi_dot
2918 >>> # Prepare some data
2919 >>> A = np.random.random((10000, 100))
2920 >>> B = np.random.random((100, 1000))
2921 >>> C = np.random.random((1000, 5))
2922 >>> D = np.random.random((5, 333))

Calls 8

dotFunction · 0.90
atleast_2dFunction · 0.90
asanyarrayFunction · 0.85
_assert_2dFunction · 0.85
_multi_dot_threeFunction · 0.85
_multi_dotFunction · 0.85
ravelMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…