NumPy strings.lower()
The numpy.strings.lower() function converts all characters in an array of strings to lowercase, applying the str.lower() method element-wise.
Syntax
</>
Copy
numpy.strings.lower(a)
Parameters
| Parameter | Type | Description |
|---|---|---|
a | array-like (StringDType, bytes_, or str_ dtype) | Input array containing strings that need to be converted to lowercase. |
Return Value
Returns an array with the same shape as the input, where all string elements are converted to lowercase.
Examples
1. Converting a Single String to Lowercase
Here, we convert a single uppercase string to lowercase.
</>
Copy
import numpy as np
# Define a single string
word = np.array("APPLE", dtype="str")
# Convert to lowercase
lower_word = np.strings.lower(word)
# Print the result
print("Lowercase string:", lower_word)
Output:
Lowercase string: apple
