dtype() function in Numpy Python by R4R Team

- dtype() is a python Numpy method that are used to find the data type of the array.

Example-

array is [1 1 2 4]
then arr.dtype return int32

Syntax-

type=np.dtype(array)


program-

#import numpy
import numpy as np

l=[1,2,3,4]
arr=np.array(l)
print("Array isn",arr)
print(arr.dtype)

l=[[1,2,3],[3,2,1],[1,0,1]]
arr=np.array(l)
print("nArray isn",arr)
print(arr.dtype)

l=['a','b','c']
arr=np.array(l)
print("nArray isn",arr)
print(arr.dtype)


output-

Array is
[1 2 3 4]
int32

Array is
[[1 2 3]
[3 2 1]
[1 0 1]]
int32

Array is
['a' 'b' 'c']
<'U1

-In this program, we have a three different lists , then we convert them into array, then by dtype we find the data type of the given array.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!