Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Array Manipulation
What will be the output of this code?
import numpy as np
arr = np.arange(8)
result = np.split(arr, 4)
print(result)
A[array([0, 1, 2, 3]), array([4, 5, 6, 7])]
B[array([0, 1, 2]), array([3, 4, 5]), array([6, 7])]
C[array([0, 1]), array([2, 3]), array([4, 5]), array([6, 7])]
DError: array cannot be split into 4 equal parts
Step-by-Step Solution
Solution:
  1. Step 1: Understand splitting by integer

    When an integer is passed, np.split() divides array into that many equal parts.
  2. Step 2: Check if equal parts possible

    Array length is 8, splitting into 4 parts means each part has 2 elements.
  3. Final Answer:

    [array([0, 1]), array([2, 3]), array([4, 5]), array([6, 7])] -> Option C
  4. Quick Check:

    Integer splits = equal parts [OK]
Quick Trick: Integer splits divide array into equal parts if possible [OK]
Common Mistakes:
  • Expecting error when split is possible
  • Wrong number of elements per part
  • Confusing split count with indices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes