A problem about torch slice

given a four dimension tensor real_ctx (64x3x128x128) and three dimension tensor mask(64x128x128)

what is " real_ctx[{{},{1},{},{}}][mask] = 2*117.0/255.0 - 1.0" for?
why there are two “[]” operation or slice ?

It seems you are using (Lua)Torch?
Where did you find this code?

It seems to me, the first slice operation gets the first channel, while the second slice applies the mask to it.

yes, it is lua code. you mean the second slice (which is mask) applies the mask to real_ctx tensor?

The mask is just used on the first channel of real_ctx.

thank you, i will go on checking it.

I would suggest to switch to PyTorch, since it’s being actively developed and has a lot of awesome features!
Have a look at the website for the install instructions.

1 Like

emm, but the code (lua) I need to refer, maybe later I will rewrite it in pytorch

sorry for disturbing you again. I run into a problem.
how to fulfill the above operation (apply a second slice to a tensor) in pytorch?

You could just slice two times or directly apply your indices to the first slice:

a = torch.randn(10, 3, 24 ,24)
a[:, 0, :, :][:, :12, :12]
# alternatively slice directly
a[:, 0, :12, :12]