Bird
0
0

You have a 2D NumPy array data with shape (6, 4). You want to split it into 3 equal parts along the first axis (rows) for separate analysis. Which code correctly does this using np.split()?

hard📝 Application Q15 of 15
NumPy - Array Manipulation
You have a 2D NumPy array data with shape (6, 4). You want to split it into 3 equal parts along the first axis (rows) for separate analysis. Which code correctly does this using np.split()?
Anp.split(data, [1, 3, 5], axis=1)
Bnp.split(data, 3, axis=1)
Cnp.split(data, [2, 4], axis=1)
Dnp.split(data, 3, axis=0)
Step-by-Step Solution
Solution:
  1. Step 1: Understand array shape and axis

    data has 6 rows and 4 columns. Splitting into 3 equal parts along rows means each part has 2 rows.
  2. Step 2: Use np.split() with correct axis and parts

    np.split(data, 3, axis=0) splits rows into 3 equal parts. axis=1 would split columns, which is not desired.
  3. Final Answer:

    np.split(data, 3, axis=0) -> Option D
  4. Quick Check:

    Split rows into 3 parts with axis=0 [OK]
Quick Trick: Use axis=0 to split rows, axis=1 for columns [OK]
Common Mistakes:
  • Splitting along wrong axis
  • Using indices instead of number for equal parts
  • Ignoring array shape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes