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.]])