How to indexing a slice of data in a N-D Tensor?

Suppose I have a batch of data with shape (2, 7, 7, 30), now if i want to rewrite:
[0, 2, 3, 0:2] [0, 2, 3, 5:7] and
[0, 3, 3, 0:2] [0, 3, 3, 5:7]
How to do it without using for loop but Pytorch API?

To illustrate my problem more clear, i want to indexing something like
[
:(whole batch),
{A 2-D tensor indicating the 1,2 dim of batch data},
{the real index i want to change}
],
How can i do it ?

Hi zgjja!

If I understand correctly what you are trying to do, you can assign to the
tensor in question after indexing into it more-or-less as you posted.

Consider:

>>> import torch
>>> torch.__version__
'1.13.0'
>>> t = torch.arange (2 * 3 * 3 * 5).reshape (2, 3, 3, 5)
>>> t[0, 2]
tensor([[30, 31, 32, 33, 34],
        [35, 36, 37, 38, 39],
        [40, 41, 42, 43, 44]])
>>> t[0, 2, 2, 0:2] = torch.tensor ([66, 99])
>>> t[0, 2]
tensor([[30, 31, 32, 33, 34],
        [35, 36, 37, 38, 39],
        [66, 99, 42, 43, 44]])

Best.

K. Frank