mindspore.numpy.size

View Source On Gitee
mindspore.numpy.size(a, axis=None)[source]

Returns the number of elements along a given axis.

Parameters
  • a (Union[int, float, bool, list, tuple, Tensor]) – Input data.

  • axis (int) – Axis along which the elements are counted. Default: None. If None, give the total number of elements.

Returns

Number of elements along the specified axis.

Supported Platforms:

Ascend GPU CPU

Raises
  • TypeError – If input is not array_like or axis is not int.

  • ValueError – If any axis is out of range or duplicate axes exist.

Examples

>>> import mindspore.numpy as np
>>> x = np.arange(10).reshape(2, 5).astype('float32')
>>> print(np.size(x))
10
>>> print(np.size(x, axis=1))
5