MCPcopy
hub / github.com/numpy/numpy / size

Function size

numpy/_core/fromnumeric.py:3564–3613  ·  view source on GitHub ↗

Return the number of elements along a given axis. Parameters ---------- a : array_like Input data. axis : None or int or tuple of ints, optional Axis or axes along which the elements are counted. By default, give the total number of elements. .

(a, axis=None)

Source from the content-addressed store, hash-verified

3562
3563@array_function_dispatch(_size_dispatcher)
3564def size(a, axis=None):
3565 """
3566 Return the number of elements along a given axis.
3567
3568 Parameters
3569 ----------
3570 a : array_like
3571 Input data.
3572 axis : None or int or tuple of ints, optional
3573 Axis or axes along which the elements are counted. By default, give
3574 the total number of elements.
3575
3576 .. versionchanged:: 2.4
3577 Extended to accept multiple axes.
3578
3579 Returns
3580 -------
3581 element_count : int
3582 Number of elements along the specified axis.
3583
3584 See Also
3585 --------
3586 shape : dimensions of array
3587 ndarray.shape : dimensions of array
3588 ndarray.size : number of elements in array
3589
3590 Examples
3591 --------
3592 >>> import numpy as np
3593 >>> a = np.array([[1,2,3],[4,5,6]])
3594 >>> np.size(a)
3595 6
3596 >>> np.size(a,axis=1)
3597 3
3598 >>> np.size(a,axis=0)
3599 2
3600 >>> np.size(a,axis=(0,1))
3601 6
3602
3603 """
3604 if axis is None:
3605 try:
3606 return a.size
3607 except AttributeError:
3608 return asarray(a).size
3609 else:
3610 _shape = shape(a)
3611 from .numeric import normalize_axis_tuple
3612 axis = normalize_axis_tuple(axis, len(_shape), allow_duplicate=False)
3613 return math.prod(_shape[ax] for ax in axis)
3614
3615
3616def _round_dispatcher(a, decimals=None, out=None):

Callers

nothing calls this directly

Calls 4

normalize_axis_tupleFunction · 0.85
asarrayFunction · 0.70
shapeFunction · 0.70
prodMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…