Pytorch tensor特定条件判断索引

torch.where() 用于将两个broadcastable的tensor组合成新的tensor,类似于c++中的三元操作符“?:”
区别于python numpy中的where()直接可以找到特定条件元素的index
Pytorch tensor特定条件判断索引

想要实现numpy中where()的功能,可以借助nonzero()
Pytorch tensor特定条件判断索引
对应numpy中的where()操作效果:
Pytorch tensor特定条件判断索引