Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Array Manipulation
What is the output of the following code?
import numpy as np
arr = np.array([10, 20, 30, 40, 50, 60])
splits = np.split(arr, [2, 4])
print(splits)
A[array([10]), array([20, 30, 40]), array([50, 60])]
B[array([10, 20, 30]), array([40, 50, 60])]
C[array([10, 20]), array([30, 40]), array([50, 60])]
D[array([10, 20]), array([30]), array([40, 50, 60])]
Step-by-Step Solution
Solution:
  1. Step 1: Understand split indices

    The list [2, 4] means split at index 2 and then at index 4.
  2. Step 2: Divide the array accordingly

    arr[:2] = [10, 20], arr[2:4] = [30, 40], arr[4:] = [50, 60]
  3. Final Answer:

    [array([10, 20]), array([30, 40]), array([50, 60])] -> Option C
  4. Quick Check:

    Split at 2 and 4 gives 3 parts [OK]
Quick Trick: Split indices mark where to cut array [OK]
Common Mistakes:
  • Misunderstanding split points
  • Off-by-one errors in slicing
  • Confusing output format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes