0
0
NumPydata~10 mins

NumPy with machine learning libraries - Interactive Code Practice

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

Complete the code to import NumPy with its common alias.

NumPy
import [1] as np
Drag options to blanks, or click blank then click option'
Asklearn
Bnumpy
Cpandas
Dmatplotlib
Attempts:
3 left
💡 Hint
Common Mistakes
Importing pandas or sklearn instead of numpy.
Not using the alias np.
2fill in blank
medium

Complete the code to convert a Python list to a NumPy array.

NumPy
arr = np.[1]([1, 2, 3, 4])
Drag options to blanks, or click blank then click option'
Aarray
Bmatrix
Clist
Dasarray
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.list which does not exist.
Using np.asarray which also works but is not the common first choice here.
3fill in blank
hard

Fix the error in the code to import the train_test_split function from scikit-learn.

NumPy
from sklearn.model_selection import [1]
Drag options to blanks, or click blank then click option'
Atrain_test_split
BtrainSplit
Csplit_train_test
Dtrain_test
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like train_test or trainSplit.
Misspelling the function name.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

NumPy
{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 as the value instead of its length.
Using the wrong comparison operator like < instead of >.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if values are positive.

NumPy
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.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of uppercase.
Using wrong comparison operators like < or ==.
Swapping keys and values.