Articles

# Convert elements in Numpy Array to upper or lower case

In this numpy tutorial, we will discuss about how to:

• convert numpy array to lowercase,
• convert numpy array to uppercase

Introduction

numpy stands for numeric python which is used to perform mathematical operations on arrays.

It is a module in which we have to import from the python.

Syntax to import:

``import numpy``

We can also use alias for the module

For example,

``import numpy as np``

We can directly use np to call the numpy module.

Array

An array is an one dimensional data structure used to store single data type data.

I.E It will only store all integer data or all string type data.or all float type data.

We can create an numpy array by using array() function.

Syntax:

``numpy.array(elements)``

where, elements are the input data elements.

### convert numpy array to lowercase

In Numpy array, we can convert the elements to lower case by using numpy.char.lower() method.

Syntax:

``numpy.char.lower(array_data)``

where, array_data is an input array

Example: convert numpy array to lowercase

``````#importing the numpy module
import numpy

#create array with upper case elements
array_data1=numpy.array(["TUTORIALS","IN","HAND"])

# converting to lower case
print(numpy.char.lower(array_data1))``````

Output:

From the above code, we converted three elements in numpy array to lowercase.

``['tutorials' 'in' 'hand']``

We have seen numpy array lowercase. Lets check on numpy array uppercase.

### convert numpy array to uppercase

In Numpy array, we can convert the elements to upper case by using numpy.char.upper() method.

Syntax:

``numpy.char.upper(array_data)``

where, array_data is an input array

Exampleconvert numpy array to uppercase

``````#importing the numpy module
import numpy

#create array with lower case elements
array_data1=numpy.array(["tutorials","in","hand"])

# converting to upper case
print(numpy.char.upper(array_data1))
``````

Output:

From the above code, we converted three elements in numpy array to uppercase..

``['TUTORIALS' 'IN' 'HAND']``

This wraps up our session on convert numpy array to lowercase and convert numpy array to uppercase.

Numpy

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com