Listing first and second values in a tensor
I know this might be a simple problem for some of you. I am not able to get the output as expected.
The input tensor is given below. 

X = tensor([[50.7500, 44.0000],
        [47.0000, 47.0000],
        [42.5000, 52.2500],
        [59.6163, 50.7097],
        [54.6682, 54.6682],
        [48.7304, 61.5956],
        [71.3156, 59.5631],
        [64.7864, 64.7864],
        [56.9515, 73.9272]])


I want two tensors A and B such that 

A = tensor([[50.7500],
        [47.0000],
        [42.5000],
        [59.6163],
        [54.6682],
        [48.7304],
        [71.3156],
        [64.7864],
        [56.9515]]) and 
B = tensor([[44.0000],
        [47.0000],
        [52.2500],
        [50.7097],
        [54.6682],
        [61.5956],
        [59.5631],
        [64.7864],
        [73.9272]])


This is what I tried till now.

idx = torch.LongTensor([0]) 
idx1 = torch.LongTensor([1]) 
A = X.index_select(1,idx)
B = X.index_select(1,idx1)


which is not giving me output as expected. Thanks in advance.

You want to pick elements from second index in the tensor, you can do this as follows:

A=X[:,0]
B=X[:,1]


The output of this will be :

print(B)
&gt;&gt;&gt;tensor([44.0000, 47.0000, 52.2500, 50.7097, 54.6682, 61.5956, 59.5631, 
64.7864, 73.9272])

print(A)                                                                                                                                                               
&gt;&gt;&gt;tensor([50.7500, 47.0000, 42.5000, 59.6163, 54.6682, 48.7304, 
71.3156, 64.7864,56.9515])


But since you want two dimensional tensors, you can then do 

A.unsqueeze(dim=1)
B.unsqueeze(dim=1)


In above case you had to explicitly tell which dimension you have to add/unsqueeze but you can avoid that by using list of indexes as below:

A = X[:, 0:1]
B = x[:, 1:2]


Using indexes of type i:i+1 will preserve the number dimensions from old tensor.
