NumPy: count() function
numpy.core.defchararray.count() function
The numpy.core.defchararray.count() function returns an array with the number of non-overlapping occurrences of substring sub in the range [start, end].
Version: 1.15.0
Syntax:
numpy.core.defchararray.count(a, sub, start=0, end=None)
Parameter:
Name | Description | Required / Optional |
---|---|---|
a: array_like of str or unicode | Input an array_like of string or unicode. | Required |
sub: str or unicode | The substring to search for. | Required |
start, end: int | Optional arguments start and end are interpreted as slice notation to specify the range in which to count. | Optional |
Return value:
out : ndarray - Output array of ints.
Example-1: numpy.count() function
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
>>> c
array(['aAaAaA', ' aA ', 'abBABba'],
dtype='|S7')
>>> np.char.count(c, 'A')
array([3, 1, 1])
>>> np.char.count(c, 'aA')
array([3, 1, 0])
>>> np.char.count(c, 'A', start=1, end=4)
array([2, 1, 1])
>>> np.char.count(c, 'A', start=1, end=3)
array([1, 0, 0])
Pictorial Presentation:
Pictorial Presentation:
Python - NumPy Code Editor:
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework