# How to get a 2d tensor from a 3d tensor simply?

I have a 3d tensor outs whose shape is like [max_seq_len, batch_size, hidden_dim].
For a simple example, the max_seq_len, batch_size, hidden_dim is set by 2, 3, 4. And i have a another 1d tensor sentence_len recording the real length of each sample in the batch that is [1, 1, 2].
Now I need to choose the last state for each sample,
1st sample, outs[1-1, 0, :]
2nd sample, outs[1-1, 1, :]
3rd sample, outs[2-1, 2, :]
Then form these selected vectors to a 2d tensor that I want.
Note that the sentence_len needs to minus 1 for the indexing.
I have tried gather and index_select but failed and stuck with it for few days. Really hope you could help me! Thanks.

I have worked it out by using slicing.
`outs[sentence_len-1, torch.arange(outs.size(1)), :]`