[Python] What does "unsqueeze" do in Pytorch?

Discussão em 'Python' iniciado por Stack, Maio 14, 2025.

  1. Stack

    Stack Membro Participativo

    The PyTorch documentation says:


    Returns a new tensor with a dimension of size one inserted at the specified position. [...]

    >>> x = torch.tensor([1, 2, 3, 4])
    >>> torch.unsqueeze(x, 0)
    tensor([[ 1, 2, 3, 4]])
    >>> torch.unsqueeze(x, 1)
    tensor([[ 1],
    [ 2],
    [ 3],
    [ 4]])​

    Continue reading...

Compartilhe esta Página