mindspore.ops.Size

class mindspore.ops.Size[source]

Returns a Scalar of type int that represents the size of the input Tensor and the total number of elements in the Tensor.

Refer to mindspore.ops.size() for more details.

Inputs:
  • input_x (Tensor) - Input parameters, the shape of tensor is \((x_1, x_2, ..., x_R)\). The data type is number.

Outputs:

int. A scalar representing the elements’ size of input_x, tensor is the number of elements in a tensor, \(size=x_1*x_2*...x_R\). The data type is an int.

Supported Platforms:

Ascend GPU CPU

Examples

>>> input_x = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32)
>>> size = ops.Size()
>>> output = size(input_x)
>>> print(output)
4