[Python] How do I get the value of a tensor in PyTorch?

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    Printing a tensor x gives:

    >>> x = torch.tensor([3])
    >>> print(x)
    tensor([3])


    Indexing x.data gives:

    >>> x.data[0]
    tensor(3)


    How do I get just a regular non-tensor value 3?

    Continue reading...

Compartilhe esta Página