PyTorch torch.greater function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.greaterIt is a function in PyTorch for element-wise greater-than comparison. Returns a tensor with True at positions where the elements of the first tensor are greater than the corresponding elements of the second tensor.

Function definition

torch.greater(input, other)

Usage example

Example

import torch

# Create two tensors
x = torch.tensor([3, 5, 2])
y = torch.tensor([2, 4, 2])

# Compare element-wise greater than
result = torch.greater(x, y)
print(result)

The output result is:

tensor([True, True, False])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other extensions