0
0
NumPydata~15 mins

np.vstack() and np.hstack() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Stacking Arrays Vertically and Horizontally with np.vstack() and np.hstack()
📖 Scenario: Imagine you are organizing data from two different sensors. Each sensor gives you a small set of readings. You want to combine these readings to analyze them together.
🎯 Goal: You will create two small arrays of sensor readings, then combine them vertically and horizontally using np.vstack() and np.hstack(). Finally, you will print the combined arrays.
📋 What You'll Learn
Create two numpy arrays named sensor1 and sensor2 with exact values
Create a variable named combined_vertical using np.vstack() to stack arrays vertically
Create a variable named combined_horizontal using np.hstack() to stack arrays horizontally
Print both combined_vertical and combined_horizontal
💡 Why This Matters
🌍 Real World
Combining sensor data or measurements from different sources is common in data science to prepare data for analysis.
💼 Career
Understanding how to stack arrays helps in data preprocessing, a key skill for data scientists and analysts working with numerical data.
Progress0 / 4 steps
1
Create two numpy arrays with sensor readings
Import numpy as np. Create a numpy array called sensor1 with values [1, 2, 3] and another numpy array called sensor2 with values [4, 5, 6].
NumPy
Need a hint?

Use np.array() to create arrays with the exact values given.

2
Stack the arrays vertically using np.vstack()
Create a variable called combined_vertical by stacking sensor1 and sensor2 vertically using np.vstack().
NumPy
Need a hint?

Use np.vstack((sensor1, sensor2)) to stack arrays vertically.

3
Stack the arrays horizontally using np.hstack()
Create a variable called combined_horizontal by stacking sensor1 and sensor2 horizontally using np.hstack().
NumPy
Need a hint?

Use np.hstack((sensor1, sensor2)) to stack arrays horizontally.

4
Print the vertically and horizontally stacked arrays
Print the variables combined_vertical and combined_horizontal to see the stacked arrays.
NumPy
Need a hint?

Use print() to display both stacked arrays.