numpy.count_reduce_items

numpy.count_reduce_items(arr, axis=None, skipna=False, keepdims=False)

Counts the number of items a reduction with the same axis and skipna parameter values would use. The purpose of this function is for the creation of reduction operations which use the item count, such as mean.

When skipna is False or arr doesn’t have an NA mask, the result is simply the product of the reduction axis sizes, returned as a single scalar.

Parameters :

arr : array_like

The array for which to count the reduce items.

axis : None or int or tuple of ints, optional

Axis or axes along which a reduction is performed. The default (axis = None) is perform a reduction over all the dimensions of the input array.

skipna : bool, optional

If this is set to True, any NA elements in the array are not counted. The only time this function does any actual counting instead of a cheap multiply of a few sizes is when skipna is true and arr has an NA mask.

keepdims : bool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.

Returns :

count : intp or array of intp

Number of items that would be used in a reduction with the same axis and skipna parameter values.

Examples

>>> a = np.array([[1,np.NA,1], [1,1,np.NA]])
>>> np.count_reduce_items(a)
6
>>> np.count_reduce_items(a, skipna=True)
4
>>> np.sum(a, skipna=True)
4
>>> np.count_reduce_items(a, axis=0, skipna=True)
array([2, 1, 1])
>>> np.sum(a, axis=0, skipna=True)
array([2, 1, 1])

Previous topic

numpy.count_nonzero

Next topic

Statistics

This Page