Bird
0
0

You have a dataset of 24 values representing 6 samples with 4 features each stored in a 1D numpy array. How do you reshape it to a 2D array with samples as rows and features as columns?

hard📝 Application Q8 of 15
NumPy - Array Manipulation
You have a dataset of 24 values representing 6 samples with 4 features each stored in a 1D numpy array. How do you reshape it to a 2D array with samples as rows and features as columns?
AUse arr.reshape(1, 24) to get a row vector
BUse arr.reshape(6, 4) to get 6 rows and 4 columns
CUse arr.reshape(24, 1) to get a column vector
DUse arr.reshape(4, 6) to get 4 rows and 6 columns
Step-by-Step Solution
Solution:
  1. Step 1: Understand data layout

    6 samples with 4 features means 6 rows and 4 columns.
  2. Step 2: Apply reshape

    Reshape to (6, 4) arranges data correctly with samples as rows.
  3. Final Answer:

    Use arr.reshape(6, 4) to get 6 rows and 4 columns -> Option B
  4. Quick Check:

    Samples as rows = reshape(6, 4) [OK]
Quick Trick: Rows = samples, columns = features [OK]
Common Mistakes:
  • Swapping rows and columns
  • Using flat reshape
  • Confusing vector shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes