Learn practical skills, build real-world projects, and advance your career

Tensor Functions

List of Tensor functions

 item()
 new_empty()
 index_fill()
 index_add()
 resize()
import torch

Function 1 - torch.tensor.item()

The function tensor.item() is used to get a number in Python from a tensor that contains single value

#Example1 to get a number from a tensor value

x = torch.tensor([[4]])
print(x)
tensor([[ 4]])