numpy.dtype() in Python

In Python, each of ndarray has a data type object associated with it. The data type object contains the following data:

  1. Type of data  – int, float, objects, etc.
  2. Data size – Total number of bytes
  3. Data byte order – little-endian or big-endian
  4. Subarray Type – If the data type is subarray its shape and data type
  5. Structured Type – the data type of each field, name of the field, etc.

Basic Syntax

Following is the basic syntax for numpy.dtype() function in Python:

numpy.dtype(object, align, copy)

And the parameters are:

ParameterDescription
ObjectInput object of which dtype should be returned
alignOptional bool. It adds padding to fields if set as true.
copyOptional bool. Creates copy of dtype object and returns built in dtype object reference.

Return Value

numpy.dtype() function returns dtype object.

Example

Following are the examples for numpy.dtype() function

Example 1

The output for the above program is as given below:

int 64

Example 2

The output for the above program is as given below:

Data Type: int16
Size: 2
Byte Order: >

Example 3

The output for the above program is as given below:

int16

Example 4

The output for the above program is as given below:

[(50,) (60,) (70,)]

Example 5

The output for the above program is as given below:

[50 60 70]

Example 6

The output for the above program is as given below:

Data Type: int64
Size: 8
Byte Order: >

LEAVE A REPLY

Please enter your comment!
Please enter your name here