快捷方式

torch.square

torch.square(input: Tensor, *, out: Optional[Tensor]) Tensor

返回一個新 Tensor,其元素為 input 中元素的平方。

引數

input (Tensor) – 輸入 Tensor。

關鍵字引數

out (Tensor, optional) – 輸出 Tensor。

示例

>>> a = torch.randn(4)
>>> a
tensor([-2.0755,  1.0226,  0.0831,  0.4806])
>>> torch.square(a)
tensor([ 4.3077,  1.0457,  0.0069,  0.2310])

文件

查閱 PyTorch 的完整開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源