mindspore.ops.Square

View Source On Gitee
class mindspore.ops.Square[source]

Returns square of a tensor element-wise.

\[out_{i} = (x_{i})^2\]
Inputs:
  • x (Tensor) - The input tensor.

Outputs:

Tensor, has the same shape and dtype as x.

Raises

TypeError – If x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

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