![]() |
VOOZH | about |
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.
A data type in NumPy is used to specify the type of data stored in a variable. Here is the list of characters available in NumPy to represent data types.
Character | Meaning |
|---|---|
b | Boolean |
f | Float |
m | Time Delta |
O | Object |
U | Unicode String |
i | Integer |
u | Unsigned Integer |
c | Complex Float |
M | DateTime |
S | String |
V | A fixed chunk of memory for other types (void) |
The list of various types of data types provided by NumPy are given below:
Data Type | Description |
|---|---|
bool_ | Boolean |
int_ | Default integer type (int64 or int32) |
intc | Identical to the integer in C (int32 or int64) |
intp | Integer value used for indexing |
int8 | 8-bit integer value (-128 to 127) |
int16 | 16-bit integer value (-32768 to 32767) |
int32 | 32-bit integer value (-2147483648 to 2147483647) |
int64 | 64-bit integer value (-9223372036854775808 to 9223372036854775807) |
uint8 | Unsigned 8-bit integer value (0 to 255) |
uint16 | Unsigned 16-bit integer value (0 to 65535) |
uint32 | Unsigned 32-bit integer value (0 to 4294967295) |
uint64 | Unsigned 64-bit integer value (0 to 18446744073709551615) |
float_ | Float values |
float16 | Half precision float values |
float32 | Single-precision float values |
float64 | Double-precision float values |
complex_ | Complex values |
complex64 | Represent two 32-bit float complex values (real and imaginary) |
complex128 | Represent two 64-bit float complex values (real and imaginary) |
We can check the datatype of Numpy array by using dtype. Then it returns the data type all the elements in the array.
int64
We can create an array with a defined data type by specifying "dtype" attribute in numpy.array() method while initializing an array.
float64 int32 complex128 bool
We can convert data type of an arrays from one type to another using astype() function.
[1 2 3] int32