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

Function count

numpy/_core/strings.py:405–446  ·  view source on GitHub ↗

Returns an array with the number of non-overlapping occurrences of substring ``sub`` in the range [``start``, ``end``). Parameters ---------- a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype sub : array-like, with ``StringDType``, ``bytes_``, or ``str_``

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

Source from the content-addressed store, hash-verified

403
404@set_module("numpy.strings")
405def count(a, sub, start=0, end=None):
406 """
407 Returns an array with the number of non-overlapping occurrences of
408 substring ``sub`` in the range [``start``, ``end``).
409
410 Parameters
411 ----------
412 a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
413
414 sub : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
415 The substring to search for.
416
417 start, end : array_like, with any integer dtype
418 The range to look in, interpreted as in slice notation.
419
420 Returns
421 -------
422 y : ndarray
423 Output array of ints
424
425 See Also
426 --------
427 str.count
428
429 Examples
430 --------
431 >>> import numpy as np
432 >>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
433 >>> c
434 array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
435 >>> np.strings.count(c, 'A')
436 array([3, 1, 1])
437 >>> np.strings.count(c, 'aA')
438 array([3, 1, 0])
439 >>> np.strings.count(c, 'A', start=1, end=4)
440 array([2, 1, 1])
441 >>> np.strings.count(c, 'A', start=1, end=3)
442 array([1, 0, 0])
443
444 """
445 end = end if end is not None else MAX
446 return _count_ufunc(a, sub, start, end)
447
448
449@set_module("numpy.strings")

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

no outgoing calls

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…