去除所有的nan並替換成0


解決方法

    angle = torch.where(torch.isnan(angle), torch.full_like(angle, 0), angle)
    print(torch.any(torch.isnan(angle)))

torch.where(condition, x, y)

  • 參數1;判斷條件
  • 參數2:滿足條件,返回x
  • 參數3:滿足條件,返回y
  • out: 返回修改的數據

torch.isnan(angle)

  • 參數angle: 輸入
  • out: 為nan的返回True, 不是的返回Flase

torch.full_like(angle, 0)

  • 參數angle: 輸入
  • 參數2: 替換成的元素


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM