December 2017
Intermediate to advanced
386 pages
10h 42m
English
To create an array with elements of a given type, specify the dtype option on the array constructor, as follows:
x = np.array([1.2, 3.4, -2.0], dtype=np.float32)
This creates an array of 32-bit floating point values:
array([ 1.20000005, 3.4000001 , -2. ], dtype=float32)
Types of array elements are represented in NumPy by objects from the dtype class, which stands for data type. The following table lists the most commonly used numeric data types available in NumPy:
| Object | Data type |
| bool_ | Boolean, stored as a byte (0 is FALSE, 1 is TRUE) |
| int32 | 32-bit signed integer |
| int64 | 64-bit signed integer |
| uint32 | 32-bit unsigned integer |
| uint64 | 64-bit unsigned integer |
| float32 | 32-bit floating ... |
Read now
Unlock full access