title: Pytorch - Apply pooling on specific dimension
body: <p>I have a 3 dimension vector. I would like to perform a 1d max pool on the second dimension.</p>
  
  <p>According to the documentation of pytorch the pooling is always performed on the last dimension.</p>
  
  <blockquote>
    <p><a href="https://pytorch.org/docs/stable/nn.html#maxpool1d" rel="nofollow noreferrer">https://pytorch.org/docs/stable/nn.html#maxpool1d</a></p>
  </blockquote>
  
  <p>For example:</p>
  
  <pre><code>&gt;&gt;&gt; x = torch.rand(5, 64, 32)
  &gt;&gt;&gt; pool = nn.MaxPool1d(2, 2)
  &gt;&gt;&gt; pool(x).shape
  torch.Size([5, 64, 16])
  </code></pre>
  
  <p>My desired output:</p>
  
  <pre><code>torch.Size([5, 32, 32])
  </code></pre>
  
  <p>How can i do that?</p>