# Compute difference of each element in a tensor with each other

**URL:** <https://discuss.pytorch.org/t/compute-difference-of-each-element-in-a-tensor-with-each-other/44087>\
**Category:** Uncategorized\
**Created:** [May 1, 2019, 8:34am UTC](https://discuss.pytorch.org/t/compute-difference-of-each-element-in-a-tensor-with-each-other/44087 "2019-05-01T08:34:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [May 1, 2019, 7:25pm UTC](https://discuss.pytorch.org/t/compute-difference-of-each-element-in-a-tensor-with-each-other/44087/2 "2019-05-01T19:25:26Z")

</div>

I think broadcasting might work:

```python
x = torch.arange(10).view(-1, 1).expand(10, 2)
x[:, 0] - x[:, 1].view(-1, 1)

```

---

_[View the full topic](https://discuss.pytorch.org/t/compute-difference-of-each-element-in-a-tensor-with-each-other/44087)._
