MCPcopy Create free account
hub / github.com/numpy/numpy / count

Method count

numpy/ma/core.py:4525–4622  ·  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

4523 get_real = real.fget
4524
4525 def count(self, axis=None, keepdims=np._NoValue):
4526 """
4527 Count the non-masked elements of the array along the given axis.
4528
4529 Parameters
4530 ----------
4531 axis : None or int or tuple of ints, optional
4532 Axis or axes along which the count is performed.
4533 The default, None, performs the count over all
4534 the dimensions of the input array. `axis` may be negative, in
4535 which case it counts from the last to the first axis.
4536
4537 .. versionadded:: 1.10.0
4538
4539 If this is a tuple of ints, the count is performed on multiple
4540 axes, instead of a single axis or all the axes as before.
4541 keepdims : bool, optional
4542 If this is set to True, the axes which are reduced are left
4543 in the result as dimensions with size one. With this option,
4544 the result will broadcast correctly against the array.
4545
4546 Returns
4547 -------
4548 result : ndarray or scalar
4549 An array with the same shape as the input array, with the specified
4550 axis removed. If the array is a 0-d array, or if `axis` is None, a
4551 scalar is returned.
4552
4553 See Also
4554 --------
4555 ma.count_masked : Count masked elements in array or along a given axis.
4556
4557 Examples
4558 --------
4559 >>> import numpy.ma as ma
4560 >>> a = ma.arange(6).reshape((2, 3))
4561 >>> a[1, :] = ma.masked
4562 >>> a
4563 masked_array(
4564 data=[[0, 1, 2],
4565 [--, --, --]],
4566 mask=[[False, False, False],
4567 [ True, True, True]],
4568 fill_value=999999)
4569 >>> a.count()
4570 3
4571
4572 When the `axis` keyword is specified an array of appropriate size is
4573 returned.
4574
4575 >>> a.count(axis=0)
4576 array([1, 1, 1])
4577 >>> a.count(axis=1)
4578 array([3, 0])
4579
4580 """
4581 kwargs = {} if keepdims is np._NoValue else {'keepdims': keepdims}
4582

Callers 15

meanMethod · 0.95
varMethod · 0.95
get_countFunction · 0.45
check_doctests_testfileFunction · 0.45
find_positionFunction · 0.45
parse_distributions_hFunction · 0.45
assert_array_compareMethod · 0.45
test_1Method · 0.45
test_99Method · 0.45
whereFunction · 0.45
averageFunction · 0.45

Calls 4

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

Tested by 3

test_1Method · 0.36
test_99Method · 0.36