問題:
I'm struggling to understand exactly how einsum
works.我正在努力理解einsum
是如何工作的。 I've looked at the documentation and a few examples, but it's not seeming to stick.我查看了文檔和一些示例,但似乎並沒有堅持。
Here's an example we went over in class:這是我們在課堂上看過的一個例子:
C = np.einsum("ij,jk->ki", A, B)
for two arrays: A
and B
.對於兩個數組: A
和B
。
I think this would take A^T * B
, but I'm not sure (it's taking the transpose of one of them right?).我認爲這需要A^T * B
,但我不確定(這是對其中一個進行轉置,對嗎?)。 Can anyone walk me through exactly what's happening here (and in general when using einsum
)?任何人都可以帶我瞭解這裏發生的事情(通常在使用einsum
)?
解決方案:
參考一: https://stackoom.com/question/1lTAj參考二: Understanding NumPy's einsum