How to index my 3D tensor inside a variable?

I have the following tensor inside a variable:

Variable containing:
( 0 ,.,.) =
-1.4806e-03 1.2613e-02 2.7224e-03 … -5.0939e-03 -1.9726e-02 5.4534e-03

( 1 ,.,.) =
4.6326e-03 1.4724e-02 1.2798e-02 … 1.7921e-02 -1.5251e-02 1.0327e-02

( 2 ,.,.) =
1.4713e-03 -6.1495e-03 1.4506e-02 … 4.3970e-03 1.0725e-02 3.5597e-02

( 7 ,.,.) =
5.1251e-02 -9.5393e-03 -4.8048e-02 … 4.9305e-02 -1.5259e-03 1.2293e-02

( 8 ,.,.) =
5.5753e-02 1.9791e-03 -4.1305e-02 … 3.6249e-02 4.1878e-02 5.2798e-03

( 9 ,.,.) =
5.6972e-02 -1.7179e-02 -3.3515e-02 … 1.5184e-02 2.1811e-02 -8.5038e-03
[torch.FloatTensor of size 10x1x500]

10 is the sequence length
1 is the batch size
500 is the embedding

How can I index this tensor so I can ge one of size 10x500? I just want to get one element of the batch.
I tried the following:

TENSOR_NAME [ : ] [ 0 ] [ : ]

But it returns the following:

[torch.FloatTensor of size 1x500]

tensor_name[:,0,:]

your code doesn’t work because tensor[:] returns itself, so tensor[:][0] is indexing on the first dimension, not the second.

1 Like

Thank you! What a silly mistake

1 Like