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)