解決方法
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: 替換成的元素