Converting a tensor into a list of tensors

I have one tensors which have many tensors in it onto which i want to iterate through loop but i have to convert it to a “list of tensors” before iterating ,so how i can convert a tensors into a list of tensors for example P1 is a tensor with 60 values in it and i want a list of tensors with 60 tensors in it.
2

Does the following help?

tensors = torch.randn(10,10)
print(tensors.shape)
for tensor in tensors:
    print(tensor.shape)

thank you for response actually i need a list of tensors a list with 10 tensors in it (this example) unfortunately i cant append the tensors

Does this work:

tensors = torch.randn(10,10)
tensorList = [None] * 10
print(tensors.shape)
for idx, tensor in enumerate(tensors):
    tensorList[idx] = tensor

for tensor in tensorList:
    print(tensor.shape)
p2 = []

torch.manual_seed(0)
p1 = torch.rand(60)

num = p1.shape[0]
for i in range(num):
   p2.append(p1[i])

This may be crass, but it’ll populate p2 with tensors of every element in p1

Would something like this be useful to iterate through p1?

for i in torch.arange(p1.shape[0]):
     print(p1[i])

thank you yes its actually worked but now i realized that i should actually get a tensors of tensors

I’m not entirely sure what you’re wanting the output to look like, but you could simply try reshaping p1 with torch.reshape or torch.view