pytorch study notes 2: Comparison of operation

 

table of Contents

 

torch.eq

torch.equal

torch.ge

torch.gt


torch.eq

torch.eq(input, other, out=None) → Tensor

Comparison element equality . The second parameter may be an amount or number of sheets with the first argument of the same type shapes.

parameter:

  • input (Tensor) - to be compared tensor
  • other (Tensor or float) - or a number of relatively tensor
  • out (Tensor, optional) - Output tensor, and shall ByteTensor type or inputthe same type

Return Value: a  torch.ByteTensor tensor, comprising the comparison results for each position (equal to 1, range 0)

Return Type: Tensor

example:

>>> torch.eq(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]]))
1  0
0  1
[torch.ByteTensor of size 2x2]

torch.equal

torch.equal(tensor1, tensor2) → bool

If two tensors have the same shape and the element value is returned True , otherwise  False.

example:

>>> torch.equal(torch.Tensor([1, 2]), torch.Tensor([1, 2]))
True
>>>a=torch.Tensor([[1,2,3],[4,5,6]])
b=torch.Tensor([[1,2,3],[4,5,6]])
c=torch.Tensor([[1,2,3],[1,2,3]])
print(torch.equal(a,b))
print(torch.equal(a,c))

True
False

torch.ge

torch.ge(input, other, out=None) → Tensor

Element-wise comparison inputand otherthat if input> = otherinput> = other. I.e. second tensor element is smaller than the first element equal to the corresponding position , satisfies the condition of 1, otherwise 0

example:

>>> torch.ge(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]]))
 1  1
 0  1
[torch.ByteTensor of size 2x2]

torch.gt

torch.gt(input, other, out=None) → Tensor

Element-wise comparison inputand other , that is, whether the INPUT> otherinput> OTHER  . The second parameter may be a number or the same as the first parameter type and shape tensor

The second tensor element is smaller than the corresponding position of the first element , satisfies the condition of 1, otherwise 0

example:

>>> torch.gt(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]]))
 0  1
 0  0
[torch.ByteTensor of size 2x2]

Guess you like

Origin blog.csdn.net/weixin_44740082/article/details/91128790