[Python] How to make an empty tensor in Pytorch?

Discussão em 'Python' iniciado por Stack, Março 11, 2025.

  1. Stack

    Stack Membro Participativo

    In python, we can make an empty list easily by doing a = []. I want to do a similar thing but with Pytorch tensors.

    If you want to know why I need that, I want to get all of the data inside a given dataloader (to create another customer dataloader). Having an empty tensor can help me gather all of the data inside a tensor using a for-loop. This is a sudo code for it.

    all_data_tensor = # An empty tensor

    for data in dataloader:
    all_data_tensor = torch.cat((all_data_tensor, data), 0)


    Is there any way to do this?

    Continue reading...

Compartilhe esta Página