指定条件返回01

PHOTO EMBED

Sat Oct 08 2022 13:31:47 GMT+0000 (Coordinated Universal Time)

Saved by @linzao

>>> x = torch.arange(5)   
>>> x
tensor([0, 1, 2, 3, 4])
>>> torch.gt(x,1)		# 大于
tensor([0, 0, 1, 1, 1], dtype=torch.uint8)
>>> x>1					# 大于
tensor([0, 0, 1, 1, 1], dtype=torch.uint8)
>>> torch.ne(x,1)		# 不等于
tensor([1, 0, 1, 1, 1], dtype=torch.uint8)
>>> x!=1				# 不等于
tensor([1, 0, 1, 1, 1], dtype=torch.uint8)
>>> torch.lt(x,3)		# 小于
tensor([1, 1, 1, 0, 0], dtype=torch.uint8)
>>> x<3					# 小于
tensor([1, 1, 1, 0, 0], dtype=torch.uint8)
>>> torch.eq(x,3)		# 等于
tensor([0, 0, 0, 1, 0], dtype=torch.uint8)
>>> x==3				# 等于
tensor([0, 0, 0, 1, 0], dtype=torch.uint8)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
content_copyCOPY

https://blog.csdn.net/tfcy694/article/details/85332953