Removing padding from tensor
I have a tensor like:
tensor([[ 9, -1, -1],
        [ 7, -1, -1],
        [ 6,  4, -1]])

What is the most efficient way to remove the padding and get something like:
[[9], [7], [ 6,  4]])

Thanks in advance for any help you can provide.

Please consider using PackedSequence in Pytorch. It's for batches with variable-length sequences, and supported by Pytorch RNN cells. You can create a PackedSequence with torch.nn.utils.rnn.pack_padded_sequence() method. Please specify padding_value to -1 since you're using -1 for paddings.
