Using flatten() and ravel() to Convert Arrays to 1D
📖 Scenario: Imagine you have a small photo represented as a 2D array of pixel brightness values. You want to convert this 2D photo into a simple list of pixels to analyze or store it easily.
🎯 Goal: You will create a 2D NumPy array, then use flatten() and ravel() methods to convert it into 1D arrays. Finally, you will print the results to see the difference.
📋 What You'll Learn
Create a 2D NumPy array with exact values
Create a variable to hold the flattened array using flatten()
Create a variable to hold the raveled array using ravel()
Print both 1D arrays to compare
💡 Why This Matters
🌍 Real World
Converting images or tables of data into a simple list helps in machine learning and data analysis tasks where flat input is needed.
💼 Career
Data scientists often reshape data arrays to prepare them for models or visualization tools.
Progress0 / 4 steps