megengine.functional.square¶
- square(x)[source]¶
Element-wise \(x^2\) function.
Calculates the square for each element \(x_i\) of the input tensor \(x\).
- Parameters
x (
Tensor
) – input tensor. Should have a floating-point data type.- Return type
- Returns
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 Type promotion rules.
Examples
>>> F.square(2) Tensor(4, dtype=int32, device=xpux:0)
Element-wise square:
>>> x = Tensor([1, -2, -3, 4]) >>> F.square(x) Tensor([ 1 4 9 16], dtype=int32, device=xpux:0)