PyTorch torch.not_equal function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.not_equalIt is a function in PyTorch for element-wise comparison of not-equal. Returns a tensor with True at positions where the elements of the first tensor are not equal to the corresponding elements of the second tensor.

Function Definition

torch.not_equal(input, other)

Usage Example

Example

import torch

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

# Element-wise comparison of inequality
result = torch.not_equal(x, y)
print(result)

The output result is:

tensor([False, True, False])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions