How to Find the Data Type of an Array in Python 


               


How to Find the Data Type of an Array in Python



Python


In this article, we show how to find the data type of an array in Python.

So an array can really be composed of many different components.

Even when using it for mathematical operations as when creating an array with numpy, there are still different data types. The array can be composed of integers or floating. Within integers, the array can be composed of 32-bit integers, and so on.

The data type of an array in Python can be found with the dtype() function.

Within this dtype() function, you specify the array. Python will then return the data type of the array.

So let's look at some examples below of finding the data type of an array in Python.



So, first, we must import numpy as np.

We then create a variable named randintegers and set it equal to, np.random.randint(1,101,5)

This produces an array of 5 integers in which we can select from integers 1 to 100.

To find the data type of this randintegers variable, we use the statement, randintegers.dtype

We see that 'int32' is returned. This means that the data type of this array is a 32-bit integer number.

We then create a variable named randfloats and set it equal to, np.random.randn(6)

This creates an array of 6 random float numbers.

We then find the data type of this array using the statement, randfloats.dtype

As output, 'float64' is returned. This tells us that the array is composed of 64-bit float numbers.

And this is all that is required to find the data type of an array in Python.


Related Resources

How to Randomly Select From or Shuffle a List in Python



HTML Comment Box is loading comments...