mindspore.ops.square
- mindspore.ops.square(input)[source]
Returns square of a tensor element-wise.
\[y_i = input_i ^ 2\]- Parameters
input (Tensor) – The input tensor with a dtype of Number.
- Returns
Tensor, has the same shape and dtype as the input.
- Raises
TypeError – If input is not a Tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> input = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32) >>> output = ops.square(input) >>> print(output) [1. 4. 9.]