0
0
NumPydata~5 mins

np.split() for dividing arrays in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.split() do in NumPy?

np.split() divides a NumPy array into multiple smaller arrays based on specified indices or sections.

Click to reveal answer
beginner
How do you split a 1D array into 3 equal parts using np.split()?

You provide the array and the number of splits. For example, np.split(arr, 3) splits into 3 equal parts if the array length is divisible by 3.

Click to reveal answer
intermediate
What happens if the array size is not divisible by the number of splits in np.split()?

np.split() will raise an error because it expects equal-sized splits unless you use np.array_split() which allows uneven splits.

Click to reveal answer
intermediate
How do you split a 2D array vertically using np.split()?

Use the axis=1 argument to split columns. For example, np.split(arr, 2, axis=1) splits the array into two parts along columns.

Click to reveal answer
intermediate
What is the difference between np.split() and np.array_split()?

np.split() requires equal-sized splits and raises an error otherwise. np.array_split() allows uneven splits without error.

Click to reveal answer
What argument do you use to split a 2D array horizontally with np.split()?
Aaxis=1
Baxis=-1
Caxis=2
Daxis=0
If you want to split an array into 4 equal parts, which of these is correct?
Anp.split(arr, [4])
Bnp.split(arr, 4)
Cnp.split(arr, 3)
Dnp.split(arr, [1,2,3])
What happens if you try np.split() on an array where equal splits are not possible?
AIt raises an error
BIt ignores extra elements
CIt splits unevenly
DIt returns the original array
Which function allows splitting arrays into unequal parts without error?
Anp.array_split()
Bnp.split()
Cnp.divide()
Dnp.chunk()
How do you specify the indices where to split an array using np.split()?
AAs a boolean mask
BAs a single integer
CAs a list of indices
DAs a string
Explain how np.split() works for dividing arrays and what happens if the splits are not equal.
Think about how you cut a cake into equal slices.
You got /3 concepts.
    Describe the difference between np.split() and np.array_split().
    One is strict about equal parts, the other is flexible.
    You got /3 concepts.