megengine.functional.square¶

square(x)[源代码]

Element-wise $$x^2$$ function.

Calculates the square for each element $$x_i$$ of the input tensor $$x$$.

x (Tensor) – input tensor. Should have a floating-point data type.

Tensor

a tensor containing the evaluated square root result for each element in $$x$$. The returned tensor must have a floating-point data type determined by 类型提升规则.

>>> F.square(2)
Tensor(4.0, device=xpux:0)


Element-wise square:

>>> x = Tensor([1, -2, -3, 4])
>>> F.square(x)
Tensor([ 1.  4.  9. 16.], device=xpux:0)