Return a boolean array which is True where the string element in array ends with suffix in Python
In this article, we are going to see how we will return a boolean array which is True where the string element in the array ends with a suffix in Python.
numpy.char.endswith() return True if the elements end with the given substring otherwise it will return False.
Syntax : np.char.endswith(input_numpy_array,’substring’)
- input_numpy_array refers to the numpy array with strings
- substring is compared with all elements present in an array
Return: Return the boolean array which includes “True” if a substring is present as a suffix and “False” if a substring is not present as a suffix.
In this example, we are creating a NumPy array with 5 strings and checking the elements’ ends with ‘ks’.
[False False True False True]
In this example, we are creating a NumPy array with 5 strings and checking the element’s ends with ‘o’.
[ True True False False False]