mindspore.ops.square

mindspore.ops.square(x)[source]

Returns square of a tensor element-wise.

\[out_{i} = (x_{i})^2\]
Parameters

x (Tensor) – The input tensor with a dtype of Number, its rank must be in [0, 7] inclusive.

Returns

Tensor, has the same shape and dtype as the x.

Raises

TypeError – If x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
>>> output = ops.square(x)
>>> print(output)
[1. 4. 9.]