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)
| 403 | |
| 404 | @set_module("numpy.strings") |
| 405 | def 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") |
no outgoing calls
searching dependent graphs…