Shortcuts

torch.square

torch.square(input, *, out=None) 张量

返回一个新的张量,其中包含input元素的平方。

Parameters

输入 (张量) – 输入张量。

Keyword Arguments

输出 (张量, 可选) – 输出张量。

示例:

>>> 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])