NumPy String: numpy.char.isspace() function
numpy.char.isspace() function
The numpy.char.isspace() function returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise.
The function is useful in text processing tasks where you need to identify and remove whitespace characters from strings.
Syntax:
numpy.char.isspace(a)
Parameter:
Name | Description | Required / Optional |
---|---|---|
a: array_like, unicode | Input array. | Required |
Return value:
Array of booleans of same shape as a.
Example: Checking for whitespace in a string
>>> import numpy as np
>>> x = np.char.isspace('thequickbrownfox')
>>> x
array(False)
In the above example, since there are no whitespace characters in the string 'thequickbrownfox', the method returns an array of False values.
Pictorial Presentation:
Example: Checking for whitespaces in a string
>>> import numpy as np
>>> y = np.char.isspace(' ')
>>> y
array(True)
In the above code, np.char.isspace(' ') returns an array with a single Boolean value True since the input string consists only of whitespaces.
Pictorial Presentation:
Example: Checking for white space using numpy.char.isspace()
>>> import numpy as np
>>> z = np.char.isspace('ABCD GHIJ')
>>> z
array(False)
In the above example, the input string 'ABCD GHIJ' contains a whitespace character at the 5th position, so the method returns an array of False values except for the 5th position which is True.
Pictorial Presentation:
Python - NumPy Code Editor:
Previous:
isnumeric()
Next:
istitle()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/numpy/string-operations/isspace.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics