# Kronecker Product

**URL:** <https://discuss.pytorch.org/t/kronecker-product/3919>\
**Category:** Uncategorized\
**Created:** [June 11, 2017, 5:18am UTC](https://discuss.pytorch.org/t/kronecker-product/3919 "2017-06-11T05:18:08Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![OCY](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ocy/32/154_2.png) [@OCY](https://discuss.pytorch.org/u/OCY)\
**Post date:** [August 21, 2018, 5:23pm UTC](https://discuss.pytorch.org/t/kronecker-product/3919/7 "2018-08-21T17:23:21Z")

</div>

Below seems to work.

```auto
def kronecker(matrix1, matrix2):
    return torch.ger(matrix1.view(-1), matrix2.view(-1)).reshape(*(matrix1.size() + matrix2.size())).permute([0, 2, 1, 3]).reshape(matrix1.size(0) * matrix2.size(0), matrix1.size(1) * matrix2.size(1))

```

---

_[View the full topic](https://discuss.pytorch.org/t/kronecker-product/3919)._
