Table of Contents
Shortcuts

# torch.kron

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

  Computes the Kronecker product, denoted by ⊗\otimes⊗, of `input` and `other`.

  If `input` is a (a 0×a 1×⋯×a n)(a_0 \times a_1 \times \dots \times a_n)(a 0​×a 1​×⋯×a n​) tensor and `other` is a (b 0×b 1×⋯×b n)(b_0 \times b_1 \times \dots \times b_n)(b 0​×b 1​×⋯×b n​) tensor, the result will be a (a 0∗b 0×a 1∗b 1×⋯×a n∗b n)(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)(a 0​∗b 0​×a 1​∗b 1​×⋯×a n​∗b n​) tensor with the following entries:

  (input⊗other)k 0,k 1,…,k n=input i 0,i 1,…,i n∗other j 0,j 1,…,j n,(\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}, (input⊗other)k 0​,k 1​,…,k n​​=input i 0​,i 1​,…,i n​​∗other j 0​,j 1​,…,j n​​,

  where k t=i t∗b t+j t k_t = i_t * b_t + j_t k t​=i t​∗b t​+j t​ for 0≤t≤n 0 \leq t \leq n 0≤t≤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. When `input` is a (m×n)(m \times n)(m×n) matrix and `other` is a (p×q)(p \times q)(p×q) matrix, the result will be a (p∗m×q∗n)(p*m \times q*n)(p∗m×q∗n) block matrix:

  A⊗B=[a 11 B⋯a 1 n B⋮⋱⋮a m 1 B⋯a m n B]\mathbf{A} \otimes \mathbf{B}=\begin{bmatrix} a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\ \vdots & \ddots & \vdots \\ a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix} A⊗B=
  ​a 11​B⋮a m 1​B​⋯⋱⋯​a 1 n​B⋮a mn​B​
  ​

  where `input` is A\mathbf{A}A and `other` is B\mathbf{B}B.

  Parameters:

    - input (Tensor) –

    - other (Tensor) –

  Keyword Arguments:

    out (Tensor, optional) – The output tensor. Ignored if `None`. 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.]])

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.