pytorch narrow is not applicable
How to do slicing in pytorch? I tried narrow and numpy slicing? Both are not working for outputing train data and test data. Is there any suggestion for solving it?
x1 = (max-min)*torch.rand(1, 21, dtype=torch.float) + min
x2 = (max-min)*torch.rand(1, 21, dtype=torch.float) + min
zipped_list = zip(x1, x2)
y = torch.empty(1, 21)
y = [torch.sin(2*x1+2) * torch.cos(0.5*x2)+0.5 for (x1, x2) in zipped_list]


print(y)

train_data = y.narrow(0,1)
test_data = y[11:21]
print(train_data)

Output is
AttributeError: 'list' object has no attribute 'narrow'

However when I do normal slicing, the test data will not be slice properly
train_data = y[0:11]
test_data = y[11:21]

Train Data is: [tensor([-0.0515,  0.4574,  0.5141,  0.4865,  0.9266,  1.0984,  0.5364,  0.7042,
         0.1741, -0.4839,  0.4332,  0.2962,  0.2311,  0.6169,  0.4321,  0.4088,
         0.2443,  0.1982,  0.7978,  0.6651, -0.4453])]
Test Data is: []


In your code, y is a PyTorch tensor:
y = torch.empty(1, 21)

Then it is replaced with a list of PyTorch tensors (actually, just one):
y = [torch.sin(2*x1+2) * torch.cos(0.5*x2)+0.5 for (x1, x2) in zipped_list]

So you need to get the first element of y that is a tensor and then slice it:
print(y[0][:5])

