NumPy - Data type Objects(dtype) Last Updated : 23 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Every ndarray has an associated data type (dtype) object. This data type object (dtype) informs us about the layout of the array. This means it gives us information about :Type of the data (integer, float, Python object etc.)Size of the data (number of bytes)Byte order of the data (little-endian or big-endian)If the data type is a sub-array, what is its shape and data type.Table of ContentCreating Data Types Objects Key Features of NumPy Data Type ObjectsCommonly Used NumPy Data TypesCreating Data Types Objects A data type object in NumPy can be created in several ways:Using Predefined Data TypesNumPy provides built-in data types like integers, floats, and strings. Python import numpy as np # Integer data type x = np.array([1, 2, 3], dtype='int32') print(x.dtype) # Float data type y = np.array([1.1, 2.2, 3.3], dtype='float64') print(y.dtype) Outputint32 float64 Using Custom Data TypesWe can define a custom dtype using the numpy.dtype constructor. Python import numpy as np # Custom structured data type x = np.dtype([('name', 'U10'), ('age', 'i4'), ('weight', 'f4')]) a = np.array([('Alice', 25, 55.5), ('Bob', 30, 72.3)], dtype=x) print(a) print(a.dtype) Output[('Alice', 25, 55.5) ('Bob', 30, 72.3)] [('name', '<U10'), ('age', '<i4'), ('weight', '<f4')] Key Features of NumPy Data Type ObjectsByte Order : The byte order can be specified using prefixes:< for little-endian.> for big-endian. Python import numpy as np # Little-endian 4-byte integer dtype_le = np.dtype('<i4') # Big-endian 4-byte integer dtype_be = np.dtype('>i4') print(dtype_le) print(dtype_be) Outputint32 >i4 Structured Data Types : NumPy supports structured or compound data types where multiple fields can have different data types. This is particularly useful for working with heterogeneous data. Python import numpy as np # Structured dtype with multiple fields person_dtype = np.dtype([('name', 'S10'), ('age', 'i4'), ('height', 'f4')]) people = np.array([('John', 28, 5.9), ('Emma', 32, 5.5)], dtype=person_dtype) print(people['name']) # Access 'name' field Output[b'John' b'Emma'] Flexible String Types : Strings in NumPy can be defined with a specific maximum length: Python import numpy as np string_array = np.array(['apple', 'banana'], dtype='S6') print(string_array) Output[b'apple' b'banana'] Datetime Data Types: NumPy supports date and time data with the datetime64 and timedelta64 types Python import numpy as np a = np.array(['2025-01-23', '2025-01-24'], dtype='datetime64') print(a) Output['2025-01-23' '2025-01-24'] Commonly Used NumPy Data TypesData TypeDescriptionExampleint3232-bit signed integer-2,147,483,648 to 2,147,483,647float6464-bit floating-point number3.14, -1.0e6complex128Complex number with float64 real and imaginary parts1+2jboolBoolean valuesTrue, FalseS or UString data'hello'datetime64Date and time'2025-01-01' Comment More infoAdvertise with us Next Article NumPy - Data type Objects(dtype) K kumar_satyam Follow Improve Article Tags : Python AI-ML-DS Python-numpy Practice Tags : python Similar Reads Data type Object (dtype) in NumPy Python Every ndarray has an associated data type (dtype) object. This data type object (dtype) informs us about the layout of the array. This means it gives us information about: Type of the data (integer, float, Python object, etc.)Size of the data (number of bytes)The byte order of the data (little-endia 3 min read Numpy data Types NumPy is a powerful Python library that can manage different types of data. Here we will explore the Datatypes in NumPy and How we can check and create datatypes of the NumPy array. DataTypes in NumPyA data type in NumPy is used to specify the type of data stored in a variable. Here is the list of c 3 min read Check data type in NumPy Numpy, is originally called numerical python, but in short, we pronounce it as Numpy. NumPy is a general-purpose array-processing package in Python. It provides high-performance multidimensional data structures like array objects and tools for working with these arrays. Numpy provides faster and mor 5 min read Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes 9 min read Python | dtype object length of Numpy array of strings In this post, we are going to see the datatype of the numpy object when the underlying data is of string type. In numpy, if the underlying data type of the given object is string then the dtype of object is the length of the longest string in the array. This is so because we cannot create variable l 3 min read Like