Index error while using a transformation in MNIST dataset

username: Benja
cooked: <p>Hi!. I am using a neural network with MNIST dataset. I want to make a transformation to this data in which I put to zero 392 pixels of the images. So I have created a list “L” with the pixels I want to be zero (for example, L = [(1,2), (23,5),…], where len(L) = 392). However I get an “Index error” and I do not know how to solve it. Thanks in advance!!. I have attached the code I am refering to.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/5/f5966d1692609e17e687f9e4b57ff30629ba4f92.png" data-download-href="https://discuss.pytorch.org/uploads/default/f5966d1692609e17e687f9e4b57ff30629ba4f92" title="Image1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/5/f5966d1692609e17e687f9e4b57ff30629ba4f92_2_690x104.png" alt="Image1" data-base62-sha1="z2zgxnuugVXb1UlmOxbReCZtaGm" width="690" height="104" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/5/f5966d1692609e17e687f9e4b57ff30629ba4f92_2_690x104.png, https://discuss.pytorch.org/uploads/default/original/3X/f/5/f5966d1692609e17e687f9e4b57ff30629ba4f92.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/5/f5966d1692609e17e687f9e4b57ff30629ba4f92.png 2x" data-dominant-color="F2F3F3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Image1</span><span class="informations">995×151 28.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/0/a/0a73dd27344b472773b6f878dcdd71a748377cfa.png" alt="Image2" data-base62-sha1="1ut0JPcfhHqtil2ZJzsWbPvAONA" width="622" height="23"><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/7/070182c4411bc0206cc96255cebb9099704fab9d.png" data-download-href="https://discuss.pytorch.org/uploads/default/070182c4411bc0206cc96255cebb9099704fab9d" title="Image3"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/070182c4411bc0206cc96255cebb9099704fab9d_2_690x91.png" alt="Image3" data-base62-sha1="ZYzUnofzrBY9lsUduhnVDsrui1" width="690" height="91" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/070182c4411bc0206cc96255cebb9099704fab9d_2_690x91.png, https://discuss.pytorch.org/uploads/default/original/3X/0/7/070182c4411bc0206cc96255cebb9099704fab9d.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/7/070182c4411bc0206cc96255cebb9099704fab9d.png 2x" data-dominant-color="E6E7E7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Image3</span><span class="informations">897×119 61.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/d/a/da28880cb99b4043ddb51b27f34f496cf5ce2916.png" alt="Image4" data-base62-sha1="v7UVswNpTId22EDz331nRENML8q" width="570" height="42"></p>

username: ptrblck
cooked: <p>Could you post a minimal, executable code snippet reproducing the issue by wrapping it into three backticks ```, please?</p>

username: Benja
cooked: <p>Okey!. I think the error can be solved just adding in class Pixels_Zero “tensor[0][self.L[i]]=0”, but I do not understand very well why this solve the problem. Thanks in advance!!</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/7/57f9c93e0b459348ceed9b73808fca44769cf8b4.png" data-download-href="https://discuss.pytorch.org/uploads/default/57f9c93e0b459348ceed9b73808fca44769cf8b4" title="Code_Snippet"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/7/57f9c93e0b459348ceed9b73808fca44769cf8b4_2_633x500.png" alt="Code_Snippet" data-base62-sha1="cygHETmFqqhsMO6LKMqGPYCll9W" width="633" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/7/57f9c93e0b459348ceed9b73808fca44769cf8b4_2_633x500.png, https://discuss.pytorch.org/uploads/default/original/3X/5/7/57f9c93e0b459348ceed9b73808fca44769cf8b4.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/7/57f9c93e0b459348ceed9b73808fca44769cf8b4.png 2x" data-dominant-color="1F2933"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Code_Snippet</span><span class="informations">759×599 62.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>