Rate this Page

torch.kron#

torch.kron(input,other,*,out=None)Tensor#

Computes the Kronecker product, denoted by\otimes, ofinput andother.

Ifinput is a(a0×a1××an)(a_0 \times a_1 \times \dots \times a_n) tensor andother is a(b0×b1××bn)(b_0 \times b_1 \times \dots \times b_n) tensor, the result will be a(a0b0×a1b1××anbn)(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n) tensor with the following entries:

(inputother)k0,k1,,kn=inputi0,i1,,inotherj0,j1,,jn,(\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} = \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},

wherekt=itbt+jtk_t = i_t * b_t + j_t for0tn0 \leq t \leq n.If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.

Supports real-valued and complex-valued inputs.

Note

This function generalizes the typical definition of the Kronecker product for two matrices to two tensors,as described above. Wheninput is a(m×n)(m \times n) matrix andother is a(p×q)(p \times q) matrix, the result will be a(pm×qn)(p*m \times q*n) block matrix:

whereinput isA\mathbf{A} andother isB\mathbf{B}.

Parameters
Keyword Arguments

out (Tensor,optional) – The output tensor. Ignored ifNone. Default:None

Examples:

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