PyTorch tensor indexing or conditional selection?
    for c in range(self.n_class):
        target[c][label == c] = 1


self.n_class is 32. and target is 32 x 1024 x 2048 tensor.

I know that target[c] select the each one of 1 x 1024 x 2048. 
But I don't understand [label == c].

Because by thumb of rule, an integer should go in the square [].

Could someone explain what second square does and how it makes sense?

PyTorch supports "Advanced Indexing." It implements the ability to accept a tensor argument to the [] operator.

The result of the == operator is a boolean mask. The [] operator is using that mask to select elements. This example below might help clarify:

&gt;&gt;&gt; x=torch.arange(0,10)
&gt;&gt;&gt; x
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
&gt;&gt;&gt; x &lt; 5
tensor([ True,  True,  True,  True,  True, False, False, False, False, False])
&gt;&gt;&gt; x[x &lt; 5]
tensor([0, 1, 2, 3, 4])
&gt;&gt;&gt; x[x &gt; 5]
tensor([6, 7, 8, 9])
&gt;&gt;&gt;


Some general docs:
https://www.pythonlikeyoumeanit.com/Module3_IntroducingNumpy/BasicIndexing.html

Advanced indexing in numpy:
https://numpy.org/doc/1.18/reference/arrays.indexing.html
