torch.reciprocal¶
- torch.reciprocal(input, *, out=None) Tensor ¶
傳回一個新的張量,其元素為
input
的倒數。注意
與 NumPy 的 reciprocal 不同,torch.reciprocal 支援整數輸入。 reciprocal 的整數輸入會自動提升為預設的純量類型。
- 參數
input (Tensor) – 輸入張量。
- 關鍵字引數
out (Tensor, optional) – 輸出張量 (可選)。
範例
>>> a = torch.randn(4) >>> a tensor([-0.4595, -2.1219, -1.4314, 0.7298]) >>> torch.reciprocal(a) tensor([-2.1763, -0.4713, -0.6986, 1.3702])