NumPy TutorialLesson 7Free preview
NumPy Data Types
This lesson is part of NumPy · All levels
Summary
Each NumPy array has a single data type (dtype) that determines how elements are stored in memory. Common types include int, float, string, and boolean; you can check them through the .dtype attribute and change them to .astype(). The right choice of dtype is important to control accuracy of calculation and memory usage.
Key points
- The .dtype attribute indicates the data type of the entire array element.
- Astype() creates a new array with the specified data type.
- Type codes such as i4 and f8 represent integers of 4 bytes and float 8 bytes.
- You can specify dtype when you create an array through np.array(data, dtype=...).
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.