This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / strings / count

function

numpy.strings:count

source: build-install/usr/lib/python3.14/site-packages/numpy/_core/strings.py :404

Signature

def   count ( a sub start = 0 end = None )

Summary

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_`` dtype

The substring to search for.

start, end : array_like, with any integer dtype

The range to look in, interpreted as in slice notation.

Returns

y : ndarray

Output array of ints

Examples

import numpy as np
c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
c
np.strings.count(c, 'A')
np.strings.count(c, 'aA')
np.strings.count(c, 'A', start=1, end=4)
np.strings.count(c, 'A', start=1, end=3)

See also

str.count

Aliases

  • numpy.char.count