Reorder h_t to batch_first

According to docs, setting parameter batch_first to True will make LSTM or GRU output tensor of shape [batch_size, seq_size, hidden_size]. But it won’t change shape of h_n and it will remain [num_channels, batch_size, hidden_size]. How to reorder h_n tensor to have shape [batch_size, num_channels, hidden_size]? (as I understand, .view() won’t work here)

h_n.transpose(0, 1) will swap dimension 0 and dimension 1.

1 Like

oh, didn’t know about that. Huge thanks!