numpy.strings.count#
- strings.count(a, sub, start=0, end=None)[source]#
傳回一個陣列,其中包含子字串
sub
在 [start
,end
] 範圍內非重疊出現的次數。- 參數::
- a類陣列,具有
StringDType
、bytes_
或str_
dtype - sub類陣列,具有
StringDType
、bytes_
或str_
dtype 要搜尋的子字串。
- start, end類陣列,具有任何整數 dtype
要搜尋的範圍,解讀方式如同切片表示法。
- a類陣列,具有
- 傳回值::
- yndarray
整數的輸出陣列
另請參閱
範例
>>> import numpy as np >>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['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])