How do you inspect the data type (dtype) of elements in a NumPy array, and what are some common dtypes?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
How do you inspect the data type (`dtype`) of the elements in a NumPy array, and what are some common dtypes?
```hint Where to look
Look at the attributes an array exposes about its elements, not only the values. For the second half, think about what NumPy chooses when you build an array without passing `dtype=`.
```
### What a Strong Answer Covers
- The attributes that report the element type and its size in bytes
- A way to test a type family (any integer, any float) instead of matching one exact name
- The common numeric dtypes and their defaults, plus the non-numeric ones (bool, string, object, datetime)
- How NumPy picks a dtype from mixed inputs and how to convert with `astype`
- Practical consequences: memory use, precision, and the cost of `object` arrays
### Follow-up Questions
- What dtype do you get from `np.array([1, 2.5])`, `np.array([1, "a"])` and `np.array([1, None])`, and why?
- Why does assigning `np.nan` into an integer array fail, and how do you work around it?
- When would you store a feature matrix as `float32` instead of `float64`, and what do you give up?
- What happens when an `int8` array overflows during arithmetic?
Overview: Asks how to check the element type of a NumPy array and which dtypes come up most often in data work. Tests knowledge of dtype attributes, default types, type promotion from mixed inputs, and the memory and precision trade-offs between integer, float and object arrays.