torch.kron¶
- torch.kron(input, other, *, out=None) Tensor ¶
計算 Kronecker 乘積,以 表示,為
input
和other
的乘積。如果
input
是 張量,且other
是 張量,則結果會是 張量,其項目如下其中 ,適用於 。如果一個張量的維度少於另一個張量,則會將其擴展維度,直到維度數量相同為止。
支援實值和複數值輸入。
注意
此函式將兩個矩陣的 Kronecker 乘積的典型定義推廣到兩個張量,如上所述。當
input
是 矩陣,且other
是 矩陣,則結果會是 區塊矩陣其中
input
為 ,而other
為 。範例
>>> mat1 = torch.eye(2) >>> mat2 = torch.ones(2, 2) >>> torch.kron(mat1, mat2) tensor([[1., 1., 0., 0.], [1., 1., 0., 0.], [0., 0., 1., 1.], [0., 0., 1., 1.]]) >>> mat1 = torch.eye(2) >>> mat2 = torch.arange(1, 5).reshape(2, 2) >>> torch.kron(mat1, mat2) tensor([[1., 2., 0., 0.], [3., 4., 0., 0.], [0., 0., 1., 2.], [0., 0., 3., 4.]])