NumPy lower() function

The lower() function is used to convert all uppercase characters into lowercase characters. If there is no uppercase characters in a given string then this method will return the original string itself.

This function calls str.lower internally for every element of any given array.

This function is locale-dependent for an 8-bit string.

Syntax of numpy.char.lower():

The syntax required to use this function is as follows:

numpy.char.lower(arr)

The above syntax indicates that lower() function takes two parameters.

In the above syntax, the argument arr represents the input array of the string on which this method will be applied.

Returned Values:

This function will return a lowercased string corresponding to the original string. And if you provide an array of strings as input, then it will return an array with all the strings in lowercase.

Example 1: With a simple string

In the code snippet below, we will use the lower() function on a string:

import numpy as np
  
a = "THIS IS A String in NUMPY"
print("The original string:")
print(a)
print("\n")
print("Applying lower() method :")  

x = np.char.lower(a)
print(x)

Copy


The original string:
THIS IS A String in NUMPY

Applying lower() method :
this is a string in numpy

Example 2:

Below we have a code snippet where we will use a string that is already in lowercase, then check the output for the same:

import numpy as np  

a = "string1"
print("The original string:")
print(a)
print("\n")
print("Applying lower() method :")  

x = np.char.lower(a)
print(x)

Output:


The original string:
string1

Applying lower() method :
string1

Example 3: With array of strings

Now let’s use the lower() function with an array of strings. It will work on each string element of the array, just like this function works with a single string.

import numpy as np

arr = np.array(['what aRE YOUR', 'Plans for Tonight', 'WILL you','ShishirKant']) 
print ("The original Input array : \n", arr) 

output = np.char.lower(arr)
print ("The output lowercased array: ", output)

Output:

The original Input array :
['what aRE YOUR' 'Plans for Tonight' 'WILL you' 'ShishirKant']
The output lowercased array: ['what are your' 'plans for tonight' 'will you' 'shishirkant']
Follow Us On