numpy dot()函数(两个数组的点积)(对于二维阵列,它是矩阵乘积)
生活随笔
收集整理的這篇文章主要介紹了
numpy dot()函数(两个数组的点积)(对于二维阵列,它是矩阵乘积)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
From multiarray.py
def dot(a, b, out=None): # real signature unknown; restored from __doc__"""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).如果“ a”和“ b”都是一維數組,則它是向量的內積(無復共軛)。- If both `a` and `b` are 2-D arrays, it is matrix multiplication,but using :func:`matmul` or ``a @ b`` is preferred.如果a和b都是二維數組,則是矩陣乘法,但是最好使用:func:matmul或a @ b。- If either `a` or `b` is 0-D (scalar), it is equivalent to :func:`multiply`and using ``numpy.multiply(a, b)`` or ``a * b`` is preferred.如果`a`或`b`均為0-D(標量),則等效于:func:`multiply`并使用``numpy.multiply(a,b)``或``a * b``為 首選。- If `a` is an N-D array and `b` is a 1-D array, it is a sum product overthe last axis of `a` and `b`.如果“ a”是一個N維數組,而“ b”是一維數組,則它是“ a”和“ b”最后一條軸上的總和。- If `a` is an N-D array and `b` is an M-D array (where ``M>=2``), it is asum product over the last axis of `a` and the second-to-last axis of `b`::如果a是N維數組,b是M維數組(其中M> = 2),則它是a的最后一個軸和a的倒數第二個軸的和積。 dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])Parameters----------a : array_likeFirst argument.第一個參數b : array_likeSecond argument.第二個參數out : ndarray, optionalOutput argument. This must have the exact kind that would be returnedif it was not used. In particular, it must have the right type, must beC-contiguous, and its dtype must be the dtype that would be returnedfor `dot(a,b)`. This is a performance feature. Therefore, if theseconditions are not met, an exception is raised, instead of attemptingto be flexible.輸出參數。 如果沒有使用,它必須具有返回的確切類型。 特別是,它必須具有正確的類型,必須是C連續的,并且它的dtype必須是為dot(a,b)返回的dtype。 這是一項性能功能。 因此,如果不滿足這些條件,則會引發異常,而不是嘗試變得靈活。Returns-------output : ndarrayReturns the dot product of `a` and `b`. If `a` and `b` are bothscalars or both 1-D arrays then a scalar is returned; otherwisean array is returned.If `out` is given, then it is returned.返回“ a”和“ b”的點積。 如果“ a”和“ b”都是標量或都是一維數組,則返回標量;否則,將返回標量。 否則返回一個數組。 如果給出`out`,則返回它。Raises------ValueErrorIf the last dimension of `a` is not the same size asthe second-to-last dimension of `b`.如果a的最后一個尺寸與b的倒數第二個尺寸不同。See Also--------vdot : Complex-conjugating dot product.tensordot : Sum products over arbitrary axes.einsum : Einstein summation convention.matmul : '@' operator as method with out parameter.Examples-------->>> np.dot(3, 4)12Neither argument is complex-conjugated:>>> np.dot([2j, 3j], [2j, 3j])(-13+0j)For 2-D arrays it is the matrix product:(對于二維陣列,它是矩陣乘積)>>> a = [[1, 0], [0, 1]]>>> b = [[4, 1], [2, 2]]>>> np.dot(a, b)array([[4, 1],[2, 2]])>>> a = np.arange(3*4*5*6).reshape((3,4,5,6))>>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3))>>> np.dot(a, b)[2,3,2,1,2,2]499128>>> sum(a[2,3,2,:] * b[1,2,:,2])499128"""pass總結
以上是生活随笔為你收集整理的numpy dot()函数(两个数组的点积)(对于二维阵列,它是矩阵乘积)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python numpy ones.li
- 下一篇: numpy np.matmul()(两个