April 2016
Beginner
156 pages
3h 23m
English
Data types are another important intrinsic aspect of a NumPy array alongside its memory layout and indexing. The data type of a NumPy array can be found by simply checking the dtype attribute of the array. Try out the following examples to check the data types of different arrays:
In [49]: x = np.random.random((10,10))
In [50]: x.dtype
Out[50]: dtype('float64')
In [51]: x = np.array(range(10))
In [52]: x.dtype
Out[52]: dtype('int32')
In [53]: x = np.array(['hello', 'world'])
In [54]: x.dtype
Out [54]: dtype('S5')
Many array creation functions provide a default array data type. For example, the np.zeros and np.ones functions create arrays that are full of floats by default. But it is possible to make them create arrays of other ...