MCPcopy
hub / github.com/numpy/numpy / count

Method count

numpy/ma/core.py:4594–4688  ·  view source on GitHub ↗

Count the non-masked elements of the array along the given axis. Parameters ---------- axis : None or int or tuple of ints, optional Axis or axes along which the count is performed. The default, None, performs the count over all t

(self, axis=None, keepdims=np._NoValue)

Source from the content-addressed store, hash-verified

4592 get_real = real.fget
4593
4594 def count(self, axis=None, keepdims=np._NoValue):
4595 """
4596 Count the non-masked elements of the array along the given axis.
4597
4598 Parameters
4599 ----------
4600 axis : None or int or tuple of ints, optional
4601 Axis or axes along which the count is performed.
4602 The default, None, performs the count over all
4603 the dimensions of the input array. `axis` may be negative, in
4604 which case it counts from the last to the first axis.
4605 If this is a tuple of ints, the count is performed on multiple
4606 axes, instead of a single axis or all the axes as before.
4607 keepdims : bool, optional
4608 If this is set to True, the axes which are reduced are left
4609 in the result as dimensions with size one. With this option,
4610 the result will broadcast correctly against the array.
4611
4612 Returns
4613 -------
4614 result : ndarray or scalar
4615 An array with the same shape as the input array, with the specified
4616 axis removed. If the array is a 0-d array, or if `axis` is None, a
4617 scalar is returned.
4618
4619 See Also
4620 --------
4621 ma.count_masked : Count masked elements in array or along a given axis.
4622
4623 Examples
4624 --------
4625 >>> import numpy.ma as ma
4626 >>> a = ma.arange(6).reshape((2, 3))
4627 >>> a[1, :] = ma.masked
4628 >>> a
4629 masked_array(
4630 data=[[0, 1, 2],
4631 [--, --, --]],
4632 mask=[[False, False, False],
4633 [ True, True, True]],
4634 fill_value=999999)
4635 >>> a.count()
4636 3
4637
4638 When the `axis` keyword is specified an array of appropriate size is
4639 returned.
4640
4641 >>> a.count(axis=0)
4642 array([1, 1, 1])
4643 >>> a.count(axis=1)
4644 array([3, 0])
4645
4646 """
4647 kwargs = {} if keepdims is np._NoValue else {'keepdims': keepdims}
4648
4649 m = self._mask
4650 # special case for matrices (we assume no other subclasses modify
4651 # their dimensions)

Callers 9

meanMethod · 0.95
varMethod · 0.95
mainFunction · 0.45
parse_distributions_hFunction · 0.45
whereFunction · 0.45
averageFunction · 0.45
build_err_msgFunction · 0.45
replace_parenthesisFunction · 0.45

Calls 4

normalize_axis_tupleFunction · 0.90
viewMethod · 0.45
getMethod · 0.45
sumMethod · 0.45

Tested by 1