title: How does the __getitem__'s idx work within PyTorch's DataLoader?
body: <p>I'm currently trying to use PyTorch's DataLoader to process data to feed into my deep learning model, but am facing some difficulty.</p>
  <p>The data that I need is of shape <code>(minibatch_size=32, rows=100, columns=41)</code>. The <code>__getitem__</code> code that I have within the custom <code>Dataset</code> class that I wrote looks something like this:</p>
  <pre><code>def __getitem__(self, idx):
      x = np.array(self.train.iloc[idx:100, :])
      return x
  </code></pre>
  <p>The reason I wrote it like that is because I want the DataLoader to handle input instances of shape <code>(100, 41)</code> at a time, and we have 32 of these single instances.</p>
  <p>However, I noticed that contrary to my initial belief the <code>idx</code> argument the DataLoader passes to the function is not sequential (this is crucial because my data is time series data). For example, printing the values gave me something like this:</p>
  <pre><code>idx = 206000
  idx = 113814
  idx = 80597
  idx = 3836
  idx = 156187
  idx = 54990
  idx = 8694
  idx = 190555
  idx = 84418
  idx = 161773
  idx = 177725
  idx = 178351
  idx = 89217
  idx = 11048
  idx = 135994
  idx = 15067
  </code></pre>
  <p>Is this normal behavior? I'm posting this question because the data  batches that are being returned are not what I initially wanted them to be.</p>
  <p>The original logic that I used to preprocess the data before using the DataLoader was:</p>
  <ol>
  <li>Read data in from either <code>txt</code> or <code>csv</code> file.</li>
  <li>Calculate how many batches are in the data and slice the data accordingly. For example, since one input instance is of shape <code>(100, 41)</code> and 32 of these form one minibatch, we usually end up with around 100 or so batches and reshape the data accordingly.</li>
  <li>One input is of shape <code>(32, 100, 41)</code>.</li>
  </ol>
  <p>I'm not sure how else I should be handling the DataLoader hook methods. Any tips or advice are greatly appreciated. Thanks in advance.</p>