torch.kron#
- torch.kron(input, other, *, out=None) Tensor #
计算
input
和other
的克罗内克积,记作 。如果
input
是一个 张量,而other
是一个 张量,则结果将是一个 张量,其中包含以下条目其中 for . If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
支持实值和复值输入。
注意
此函数将两个矩阵的典型克罗内克积定义推广到两个张量,如上所述。当
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.]])