w3resource

NumPy String: numpy.char.lower() function

numpy.char.lower() function

The numpy.char.lower() function returns an array with the elements converted to lowercase.

This function is useful in data preprocessing, text analysis etc.

Syntax:

numpy.char.lower(a)

Parameter:

Name Description Required /
Optional
a: array_like, {str, unicode} Input array. Required

Return value:

out : ndarray, {str, unicode} - Output array of str or unicode, depending on input type.

Example: Converting elements of a string array to lowercase using NumPy

>>> import numpy as np
>>> x = np.array(['A1B C', '1BCA', 'BCA1']); x
array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')
>>> np.char.lower(x)
array(['a1b c', '1bca', 'bca1'], dtype='*lt;U5')

In the above code a one-dimensional NumPy array x is created with three string elements: 'A1B C', '1BCA', and 'BCA1'. The variable x is then printed, showing the array with a data type of '<U5', which represents a Unicode string with a maximum length of 5 characters.
Then the numpy.char.lower() function is called with the input array x. This function returns a new array with the same shape as the input array, where each element is a lowercase version of the corresponding element in the input array.

Pictorial Presentation:

NumPy String operation: lower() function

Python - NumPy Code Editor:

Previous: ljust()
Next: lstrip()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://w3resource.com/numpy/string-operations/lower.php