# Multidimentional tensor max

**URL:** <https://discuss.pytorch.org/t/multidimentional-tensor-max/68213>\
**Category:** Uncategorized\
**Created:** [January 31, 2020, 9:08am UTC](https://discuss.pytorch.org/t/multidimentional-tensor-max/68213 "2020-01-31T09:08:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam3](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sam3/32/31081_2.png) [@Sam3](https://discuss.pytorch.org/u/Sam3)\
**Post date:** [January 31, 2020, 9:08am UTC](https://discuss.pytorch.org/t/multidimentional-tensor-max/68213/1 "2020-01-31T09:08:05Z")

</div>

Hi,  
I have a multi-dimensional tensor, in wich way can i get the maximum over all dimensions and the multi-dimensional index for the maximum?

---

<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:** [February 1, 2020, 7:41am UTC](https://discuss.pytorch.org/t/multidimentional-tensor-max/68213/2 "2020-02-01T07:41:46Z")

</div>

This code should work:

```python
x = torch.randn(100, 100, 100)
x_max = torch.max(x)
idx_max = (x == x_max).nonzero()

```

---

<div class="post-metadata">

**Author:** ![Sam3](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sam3/32/31081_2.png) [@Sam3](https://discuss.pytorch.org/u/Sam3)\
**Post date:** [February 1, 2020, 5:33pm UTC](https://discuss.pytorch.org/t/multidimentional-tensor-max/68213/3 "2020-02-01T17:33:00Z")

</div>

Thank you so much 😊
