Defining structured dtypes in NumPy
📖 Scenario: You work in a small company that collects information about employees. You want to store each employee's name, age, and salary in a structured way using NumPy.
🎯 Goal: Create a NumPy structured array with a custom data type that holds employee name as a string, age as an integer, and salary as a float. Then, display the array.
📋 What You'll Learn
Create a structured dtype with fields: 'name' (string of length 10), 'age' (integer), and 'salary' (float).
Create a NumPy array called
employees with exactly 3 entries using the structured dtype.Fill the array with these exact employee data: ('Alice', 30, 70000.0), ('Bob', 25, 48000.5), ('Charlie', 35, 120000.0).
Print the
employees array to show the stored data.💡 Why This Matters
🌍 Real World
Structured dtypes help store complex data like employee records, sensor data, or any tabular data with mixed types efficiently in NumPy.
💼 Career
Knowing how to define and use structured dtypes is useful for data scientists and analysts working with heterogeneous datasets in Python.
Progress0 / 4 steps