捷徑

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 的完整開發者文件

查看文件

教學

取得針對初學者和進階開發者的深入教學

查看教學

資源

尋找開發資源並獲得您的問題解答

查看資源