評價此頁

torch.result_type#

torch.result_type(tensor1, tensor2) dtype#

返回對提供的輸入張量執行算術運算後得到的 torch.dtype。有關型別提升邏輯的更多資訊,請參閱型別提升 文件

引數
  • tensor1 (TensorNumber) – 輸入張量或數字

  • tensor2 (TensorNumber) – 輸入張量或數字

示例

>>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
torch.float32
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
torch.uint8