Signup/Sign In
LAST UPDATED: DECEMBER 10, 2020

NumPy lower() function

In this tutorial, we will cover lower() function of the char module in the Numpy library.

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)


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)


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','Studyonight']) 
print ("The original Input array : \n", arr) 

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


The original Input array :
['what aRE YOUR' 'Plans for Tonight' 'WILL you' 'Studyonight']
The output lowercased array: ['what are your' 'plans for tonight' 'will you' 'studyonight']

Summary

In this tutorial we have covered the lower() function of the Numpy Library. We covered how it is used with its syntax and values returned by this function along with a few examples to see the function in action.



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.