Rate this Page

torch.kron#

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

Computes the Kronecker product, denoted by , of input and other.

If input is a (a0×a1××an) tensor and other is a (b0×b1××bn) tensor, the result will be a (a0b0×a1b1××anbn) tensor with the following entries:

(inputother)k0,k1,,kn=inputi0,i1,,inotherj0,j1,,jn,

where kt=itbt+jt for 0tn. 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) matrix and other is a (p×q) matrix, the result will be a (pm×qn) block matrix:

AB=a11Bam1Ba1nBamnB

where input is A and other is B.

Parameters
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.