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

Function count

numpy/core/defchararray.py:523–565  ·  view source on GitHub ↗

Returns an array with the number of non-overlapping occurrences of substring `sub` in the range [`start`, `end`]. Calls `str.count` element-wise. Parameters ---------- a : array_like of str or unicode sub : str or unicode The substring to search for. start

(a, sub, start=0, end=None)

Source from the content-addressed store, hash-verified

521
522@array_function_dispatch(_count_dispatcher)
523def count(a, sub, start=0, end=None):
524 """
525 Returns an array with the number of non-overlapping occurrences of
526 substring `sub` in the range [`start`, `end`].
527
528 Calls `str.count` element-wise.
529
530 Parameters
531 ----------
532 a : array_like of str or unicode
533
534 sub : str or unicode
535 The substring to search for.
536
537 start, end : int, optional
538 Optional arguments `start` and `end` are interpreted as slice
539 notation to specify the range in which to count.
540
541 Returns
542 -------
543 out : ndarray
544 Output array of ints.
545
546 See Also
547 --------
548 str.count
549
550 Examples
551 --------
552 >>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
553 >>> c
554 array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
555 >>> np.char.count(c, 'A')
556 array([3, 1, 1])
557 >>> np.char.count(c, 'aA')
558 array([3, 1, 0])
559 >>> np.char.count(c, 'A', start=1, end=4)
560 array([2, 1, 1])
561 >>> np.char.count(c, 'A', start=1, end=3)
562 array([1, 0, 0])
563
564 """
565 return _vec_string(a, int_, 'count', [sub, start] + _clean_args(end))
566
567
568def _code_dispatcher(a, encoding=None, errors=None):

Callers 15

test_testAverage2Method · 0.90
test_basic1dMethod · 0.90
test_basic2dMethod · 0.90
test_oddfeatures_1Method · 0.90
test_count_funcMethod · 0.90
test_countMethod · 0.90
countMethod · 0.85
test_generator_sourceMethod · 0.85
_medianFunction · 0.85
test_testBasic1dMethod · 0.85

Calls 2

_vec_stringFunction · 0.90
_clean_argsFunction · 0.85

Tested by 14

test_testAverage2Method · 0.72
test_basic1dMethod · 0.72
test_basic2dMethod · 0.72
test_oddfeatures_1Method · 0.72
test_count_funcMethod · 0.72
test_countMethod · 0.72
test_generator_sourceMethod · 0.68
test_testBasic1dMethod · 0.68
test_testBasic2dMethod · 0.68
test_xtestCountMethod · 0.68