# Tensor slicing using another tensor

I have a 2D tensor and want to select elements from it according to another Tensor with a list of cell ids.
I am using `Tensor_A[Tensor_B]` but it is behaving not as I expected.

Why slicing a tensor using another tensor behaves differently than using a numpy array? See below for example:

``````In [1]: import torch
import numpy as np

In [3]: A = torch.randint(0,10, size=(3,4))
tensor([[6, 6, 5, 3],
[1, 7, 7, 3],
[5, 8, 5, 4]])

In [5]: A[np.array([[0,0],[1,1]])]
Out[5]: tensor([6, 6])

In [6]: A[torch.tensor([[0,0],[1,1]])]
Out[6]:
tensor([[[6, 6, 5, 3],
[6, 6, 5, 3]],

[[1, 7, 7, 3],
[1, 7, 7, 3]]])
``````

What is the difference between slicing using numpy and a tensor?

If you are using the numpy array as the index, you will get the same result as using a nested `list`:

``````A[[[0,0],[1,1]]]
> tensor([6, 6])
``````

To reproduce this behavior, you would need to split the index tensor:

``````A[torch.tensor([[0,0],[1,1]]).split(1)]
> tensor([6, 6])
``````