NumPy: startswith() function
numpy.core.defchararray.startswith() function
The numpy.core.defchararray.startswith() function returns a boolean array which is True where the string element in a starts with prefix, otherwise False.
Calls str.startswith element-wise.
Syntax:
numpy.core.defchararray.startswith(a, prefix, 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 |
prefix: str | Input string or unicode | Required |
start, end: int | With optional start, test beginning at that position. With optional end, stop comparing at that position. | Optional |
Return value:
out : ndarray - Array of booleans.
Note:
The 'chararray' class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of 'dtype' 'object_', 'string_' or 'unicode_', and use the free functions in the 'numpy.char' module for fast vectorized string operations.
Some methods will only be available if the corresponding string method is available in your version of Python.
The preferred alias for 'defchararray' is 'numpy.char'.
Example-1: numpy.startswith() function
>>> import numpy as np
>>> x = np.char.startswith('dishonoest man', 'dis', start=0, end=None)
>>> x
array(True)
Pictorial Presentation:
Example-2: numpy.startswith() function
>>> import numpy as np
>>> y = np.char.startswith('honoest man', 'prefix', start=0, end=None)
>>> y
array(False)
Pictorial Presentation:
Python - NumPy Code Editor:
Previous:
rindex()
Next:
chararray()
- 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