title: pytorch custom dataset: DataLoader returns a list of tensors rather than tensor of a list
body: <pre><code>import torch
  
  class Custom_Dataset(torch.utils.data.dataset.Dataset):
      def __init__(self, _dataset):
          self.dataset = _dataset
  
      def __getitem__(self, index):
          example, target = self.dataset[index]
          return example, target
  
      def __len__(self):
          return len(self.dataset)
  
  train_data = [([1, 3, 5], 0),
                ([2, 4, 6], 1)]
  train_loader = torch.utils.data.DataLoader(dataset=Custom_Dataset(train_data),
                                             batch_size=1,
                                             shuffle=False)
  
  for inputs, targets in train_loader:
      print(inputs)
      print(targets)
  </code></pre>
  
  <p>I'm defining my training data as <code>[([1, 3, 5], 0), ([2, 4, 6], 1)]</code>: input(<code>[1, 3, 5]</code>) paired target (<code>0</code>).</p>
  
  <p>But when I fetch data from data loader, it becomes:</p>
  
  <pre><code>[tensor([1]), tensor([3]), tensor([5])]
  tensor([0])
  </code></pre>
  
  <p>How do I get instead:</p>
  
  <pre><code>tensor([[1],
          [3],
          [5]])
  tensor([0])
  </code></pre>
  
  <p>?</p>
  
  <p>I know <code>torch.stack</code> can do the trick, but can I convert it in my custom dataset class?</p>