0
0
NumPydata~10 mins

np.split() for dividing arrays in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to split the array into 3 equal parts.

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
splits = np.split(arr, [1])
Drag options to blanks, or click blank then click option'
A6
B2
C4
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length of the array instead of the number of splits.
Using a number that does not divide the array length evenly.
2fill in blank
medium

Complete the code to split the array at the specified indices.

NumPy
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
splits = np.split(arr, [1])
Drag options to blanks, or click blank then click option'
A[0, 2]
B[1, 3]
C[2, 4]
D[3, 5]
Attempts:
3 left
💡 Hint
Common Mistakes
Using indices that are out of range.
Confusing the indices with the number of splits.
3fill in blank
hard

Fix the error in the code to split the array into 4 parts.

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8])
splits = np.split(arr, [1])
Drag options to blanks, or click blank then click option'
A[2, 4, 6]
B4
C[1, 3, 5]
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the number 4 instead of indices for unequal splits.
Using indices that do not split the array evenly.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
lengths = { [1] : [2] for word in words if len(word) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.upper()
Dlen(word) - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length as the key instead of the word.
Using incorrect expressions for length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 letters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
lengths = { [1] : [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Not filtering words by length.