torch.where(),torch.gather()

torch.where()

torch.where(),torch.gather()

给定一个条件cond,满足条件的取x对应位置元素,不满足的取y对应元素

torch.where(),torch.gather()

torch.gather()

实际上是一个查表操作

torch.where(),torch.gather()

先计算出满足条件的索引index,再利用得到的index从需要查找的数据中进行查找

 

torch.where(),torch.gather()