# megengine.functional.sqrt¶

sqrt(x)[源代码]

Element-wise $$\operatorname{sqrt}(x)$$ function.

Calculates the square root for each element $$x_i$$ of the input tensor $$x$$. After rounding, each result must be indistinguishable from the infinitely precise result (as required by IEEE 754).

This function has domain [0, +infinity] and codomain [0, +infinity].

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 类型提升规则.

Special cases

For floating-point operands,

• If $$x_i$$ is NaN, the result is NaN.

• If $$x_i$$ is less than 0, the result is NaN.

• If $$x_i$$ is +0, the result is +0.

• If $$x_i$$ is -0, the result is -0.

• If $$x_i$$ is +infinity, the result is +infinity.

>>> F.sqrt(4)
Tensor(2.0, device=xpux:0)


Element-wise square root:

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