14_pytorch.where,pytorch.gather
生活随笔
收集整理的這篇文章主要介紹了
14_pytorch.where,pytorch.gather
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.14.高級OP
1.14.1.where
給定一個條件cond,滿足條件的取x對應位置元素,不滿足的取y對應元素。
代碼示例:
# -*- coding: UTF-8 -*-import torcha = torch.randn(3, 5) b = torch.ones(3, 5)print(a) """ 輸出結果: tensor([[ 1.4446, 0.4373, 0.6730, 0.1549, -1.0664],[ 0.4106, 0.3604, 1.3719, -0.9672, 0.7382],[ 0.2602, -0.3008, 0.8865, -0.2711, 0.1028]]) """ print(b) """ 輸出結果: tensor([[1., 1., 1., 1., 1.],[1., 1., 1., 1., 1.],[1., 1., 1., 1., 1.]]) """print(torch.where(a > 0, a, b)) """ 輸出結果: tensor([[1.4446, 0.4373, 0.6730, 0.1549, 1.0000],[0.4106, 0.3604, 1.3719, 1.0000, 0.7382],[0.2602, 1.0000, 0.8865, 1.0000, 0.1028]]) """1.14.2.gather
舉例
總結
以上是生活随笔為你收集整理的14_pytorch.where,pytorch.gather的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 烟熏过的兔子肉是不是会柴起来?
- 下一篇: 三餐最适合什么时候吃?