我有以下乘法例程:
import numpy as np
a = np.random.rand(3,3)
b = np.random.rand(3,50,50)
res = np.zeros((3, 50, 50))
for i in range(50):
for j in range(50):
res[:,i,j] = a @ b[:,i,j]
什么是einsum等價表達?
最好的祝福
uj5u.com熱心網友回復:
可能想復習愛因斯坦求和符號:
res = np.einsum('ij, jkl -> ikl', a, b)
在這種情況下,np.tensordot也很有用:
np.tensordot(a ,b, 1).shape
Out[]: (3, 50, 50)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/464534.html
標籤:Python python-3.x 麻木的 numpy-ndarray numpy-einsum
下一篇:傳遞背景關系的最佳方式
