numpy.char.count#
- char.count(a,sub,start=0,end=None)[source]#
Returns an array with the number of non-overlapping occurrences ofsubstring
subin the range [start,end).- Parameters:
- aarray-like, with
StringDType,bytes_, orstr_dtype - subarray-like, with
StringDType,bytes_, orstr_dtype The substring to search for.
- start, endarray_like, with any integer dtype
The range to look in, interpreted as in slice notation.
- aarray-like, with
- Returns:
- yndarray
Output array of ints
See also
Examples
>>>importnumpyasnp>>>c=np.array(['aAaAaA',' aA ','abBABba'])>>>carray(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')>>>np.strings.count(c,'A')array([3, 1, 1])>>>np.strings.count(c,'aA')array([3, 1, 0])>>>np.strings.count(c,'A',start=1,end=4)array([2, 1, 1])>>>np.strings.count(c,'A',start=1,end=3)array([1, 0, 0])
On this page