numpy-einsum

    2熱度

    1回答

    我有3軸的數組: a = [[[1,2,3], [4,5,6], [7,8,9]], [[9,8,7], [6,5,4], [3,2,1]], [[1,1,1], [2,2,2], [3,3,3]]] 我想使用einsum非迭代地採取各向量的點積在「A」與基質: m = [[a, b, c], [d, e, f], [g, h, i]] 這樣 pro

    2熱度

    1回答

    我有形狀(n,n)的矩陣A和形狀(p,n)的另一個矩陣b。我需要一個矩陣C,使得我目前在做 C[i] = (A * b[i, np.newaxis, :]) * b[i, :, np.newaxis] ,通過做np.matlib.repmat(A),然後使用np.einsum如下 A1 = np.matlib.repmat(A, p, 1).reshape(p, n, n) C = np.e

    3熱度

    1回答

    我知道我可以做np.subtract.outer(x, x)。如果x已經形狀(n,),那麼我最終得到一個形狀爲的陣列。不過,我有一個形狀爲(n, 3)的x。我想輸出形狀爲(n, n, 3)的東西。我該怎麼做呢?也許np.einsum?