Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
5 functions of Torch Tensor
Those 5 next function creates a specific type of new tensors or they modify the values of the tensors with specific rules
-torch.new_full
-torch.new_empty
-torch.clamp
-torch.cos
-torch.div
# Import torch and other required modules
import torch
Function 1 - torch.newfull
Returns a tensor of a specific given size with a specific given value
# Example 1 - create a full tensor with an 2D array of size [3][3] with all values 2
tensor1 = torch.ones((2,), dtype=torch.float64)
tensor1=tensor1.new_full((3, 3), 2)
tensor1
tensor([[2., 2., 2.],
[2., 2., 2.],
[2., 2., 2.]], dtype=torch.float64)
It creates a full tensor with an 2D array of size [3][3] with all values 2