torch.kron¶
- torch.kron(input, other, *, out=None) Tensor¶
計算
input和other的克羅內克積(Kronecker product),記為 。如果
input是一個 張量,而other是一個 張量,則結果將是一個 張量,其元素如下所示:其中 ,對於 成立。如果一個張量的維度少於另一個,則會對其進行 unsqueeze 操作,直到兩者維度相同。
支援實值和複數值輸入。
注意
如上所述,此函式將兩個矩陣的典型克羅內克積定義推廣到兩個張量。當
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.]])