NumPy strings.islower()
The numpy.strings.islower()
function checks whether all cased characters in each string element of an input array are lowercase.
At least one cased character must be present for it to return True
.
Syntax
</>
Copy
numpy.strings.islower(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
Parameters
Parameter | Type | Description |
---|---|---|
x | array_like (StringDType, bytes_, or str_ dtype) | Input array containing string elements. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array where the result is stored. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to check. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the function. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines if subclasses of ndarray are preserved in the output. |
Return Value
Returns a boolean array indicating whether all cased characters in each element are lowercase and at least one cased character is present. If the input is a scalar, a scalar boolean value is returned.
Examples
1. Checking Lowercase Strings in an Array
We check if each string in an array consists only of lowercase characters.
</>
Copy
import numpy as np
# Define an array of strings
strings = np.array(["hello", "World", "python", "123"])
# Check which strings are completely lowercase
result = np.strings.islower(strings)
# Print the results
print("Input strings:", strings)
print("Are they lowercase?", result)
Output:
Input strings: ['hello' 'World' 'python' '123']
Are they lowercase? [ True False True False]

2. Using the out
Parameter
Using an output array to store results instead of creating a new array.
</>
Copy
import numpy as np
# Define an array of strings
strings = np.array(["lowercase", "MIXEDcase", "UPPER", "test123"])
# Create an output array with the same shape
output_array = np.empty_like(strings, dtype=bool)
# Check lowercase strings and store the result in output_array
np.strings.islower(strings, out=output_array)
# Print the results
print("Computed results:", output_array)
Output:
Computed results: [ True False False False]

3. Using the where
Parameter
Using a condition to check lowercase strings only for selected elements.
</>
Copy
import numpy as np
# Define an array of strings
strings = np.array(["apple", "Banana", "grape", "123"])
# Define a mask (check only where mask is True)
mask = np.array([True, False, True, False])
# Check lowercase strings where mask is True
result = np.strings.islower(strings, where=mask)
# Print the results
print("Computed results with mask:", result)
Output:
Computed results with mask: [ True False True False]

The lowercase check is performed only for elements where mask=True
. The other values remain unchanged.