mindspore.ops.size

mindspore.ops.size(input_x)[source]

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

Parameters

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

Returns

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.

Raises

TypeError – If input_x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

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