Here’s the list of functions with their descriptions:
torch.abs(input)– Returns the absolute value of each element in the input tensor.torch.ceil(input)– Returns the smallest integer greater than or equal to each element in the input tensor (ceiling function).torch.floor(input)– Returns the largest integer less than or equal to each element in the input tensor (floor function).torch.clamp(input, min=None, max=None)– Clamps all elements in the input tensor to the range[min, max].torch.std(input, unbiased=True)– Returns the standard deviation of all elements in the input tensor.torch.prod(input, dim=None)– Returns the product of all elements in the input tensor or along the specified dimension.torch.unique(input, sorted=False, return_inverse=False)– Returns the unique elements of the input tensor.
Examples:
torch.abs(input)
- Description: Returns the absolute value of each element in the input tensor.
- Example:
python a = torch.tensor([-1.5, 2.3, -3.7]) result = torch.abs(a) print(result)
Output:tensor([1.5000, 2.3000, 3.7000])
torch.ceil(input)
- Description: Returns the smallest integer greater than or equal to each element in the input tensor (ceiling function).
- Example:
python a = torch.tensor([1.2, 2.8, -3.5]) result = torch.ceil(a) print(result)
Output:tensor([ 2., 3., -3.])
torch.floor(input)
- Description: Returns the largest integer less than or equal to each element in the input tensor (floor function).
- Example:
python a = torch.tensor([1.2, 2.8, -3.5]) result = torch.floor(a) print(result)
Output:tensor([ 1., 2., -4.])
torch.clamp(input, min=None, max=None)
- Description: Clamps all elements in the input tensor into the range
[min, max]. Ifminormaxare not specified, they are ignored. - Example:
python a = torch.tensor([-1, 2, 3, 4, 5]) result = torch.clamp(a, min=0, max=4) print(result)
Output:tensor([0, 2, 3, 4, 4])
torch.std(input, unbiased=True)
- Description: Returns the standard deviation of all elements in the input tensor. By default, it uses the unbiased estimator.
- Example:
python a = torch.tensor([1.0, 2.0, 3.0, 4.0]) result = torch.std(a) print(result)
Output:tensor(1.2909)
torch.prod(input, dim=None)
- Description: Returns the product of all elements in the input tensor along the specified dimension
dim. Ifdimis not specified, it returns the product of all elements. - Example:
python a = torch.tensor([1, 2, 3, 4]) result = torch.prod(a) print(result)
Output:tensor(24)
torch.unique(input, sorted=False, return_inverse=False)
- Description: Returns the unique elements of the input tensor. If
sorted=True, the output is sorted.return_inverse=Truereturns an additional tensor showing the indices for reconstructing the input. - Example:
python a = torch.tensor([1, 2, 2, 3, 4, 4, 5]) result = torch.unique(a) print(result)
Output:tensor([1, 2, 3, 4, 5])