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?