# Fill a 3D tensor in an arbitrary dimension given 2D indices

**URL:** <https://discuss.pytorch.org/t/fill-a-3d-tensor-in-an-arbitrary-dimension-given-2d-indices/63966>\
**Category:** Uncategorized\
**Created:** [December 13, 2019, 11:44am UTC](https://discuss.pytorch.org/t/fill-a-3d-tensor-in-an-arbitrary-dimension-given-2d-indices/63966 "2019-12-13T11:44:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuanFMontesinos](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/juanfmontesinos/32/76115_2.png) [@JuanFMontesinos](https://discuss.pytorch.org/u/JuanFMontesinos)\
**Post date:** [December 13, 2019, 11:44am UTC](https://discuss.pytorch.org/t/fill-a-3d-tensor-in-an-arbitrary-dimension-given-2d-indices/63966/1 "2019-12-13T11:44:42Z")

</div>

Is there any faster way to using advanced indexing?

```auto
import torch

sp = torch.rand(3, 4, 4)
indices = sp.max(dim=0)[1]
gt = torch.zeros_like(sp)

for idx, sp_i in enumerate(gt):
    sp_i.masked_fill_(indices == idx, 1.)

```
