mindspore.Tensor.numel

View Source On Gitee
Tensor.numel()[source]

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

Returns

int. A scalar representing the total of elements in the Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor
>>> input_x = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32)
>>> print(input_x.numel())
4