0
0
NumPydata~10 mins

np.savez() for multiple 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 save two arrays into a single .npz file using np.savez.

NumPy
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
np.savez('data.npz', [1]=arr1, arr2=arr2)
Drag options to blanks, or click blank then click option'
Aarray1
Bdata1
Carr1
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name that does not match the variable name.
Forgetting to name the first array.
2fill in blank
medium

Complete the code to load the arrays saved in 'data.npz' and print the first array.

NumPy
import numpy as np
loaded = np.load('data.npz')
print(loaded[[1]])
Drag options to blanks, or click blank then click option'
A'arr1'
B'arr2'
C'array1'
D'data1'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong key name to access the array.
Forgetting to use quotes around the key.
3fill in blank
hard

Fix the error in the code to save three arrays named 'a', 'b', and 'c' into 'arrays.npz'.

NumPy
import numpy as np
a = np.array([1, 2])
b = np.array([3, 4])
c = np.array([5, 6])
np.savez('arrays.npz', a, [1], c)
Drag options to blanks, or click blank then click option'
Aarr_b
Bb
Carray_b
Db_array
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name that does not match the variable.
Forgetting to include the second array.
4fill in blank
hard

Fill both blanks to create a dictionary of array lengths for words longer than 3 characters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length.
Using the wrong comparison operator.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

NumPy
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting keys to uppercase.
Using the wrong comparison operator.
Using keys instead of values for the dictionary values.