How to assign value in 5-dimension tensor

hi, i research to training for object tracker using pytorch.
i have question about how to assign value in 5-dimension tensor.

tcls = torch.LongTensor(nB, nA, nGh, nGw, nC).fill_(0).cuda() # create 5-dim tensor

gt_index = gt_index_map[fg_index] # fg_index shape is nA x nGh x nGw
cls_index = t_cls[gt_index] # get class id from ground truth
cls_index = cls_index.view(-1, 1)

print(’------------- First ----------------’)
target = tcls[b][fg_index]
target.scatter_(1, cls_index, 1)

print(’--------------Second ------------------’)
tcls[b][fg_index].scatter_(1, cls_index, 1)

First code was changed greatly! but second code is not changed…
why not change value 0 to 1 in that tensor ??

tcls[b][fg_index].scatter_(1, cls_index, 1) applies the scatter_ on the slice (which is apparently a copy in this case) so that the manipulation won’t be applied on the original tensor.

Could you post a small code snippet with some desired values so that we could have a look at it?

PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier :wink: