torch.kron#
- torch.kron(input, other, *, out=None) Tensor#
計算
input和other的克羅內克積,表示為 。如果
input是一個 張量和other是一個 張量,結果將是一個 張量,包含以下條目其中 for . 如果一個張量的維度少於另一個張量,它會被擴充套件(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.]])