Skip to Content
NumPy Essentials
book

NumPy Essentials

by Jaidev Deshpande, Leo (Liang-Huan) Chin, Tanmay Dutta, Shane Holloway
April 2016
Beginner content levelBeginner
156 pages
3h 23m
English
Packt Publishing
Content preview from NumPy Essentials

Array data types

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SciPy and NumPy

SciPy and NumPy

Eli Bressert
Python Distilled

Python Distilled

David M. Beazley

Publisher Resources

ISBN: 9781784393670Supplemental Content