0
0
NumPydata~10 mins

When NumPy is not fast enough - 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 the library that helps speed up Python loops.

NumPy
import [1]
Drag options to blanks, or click blank then click option'
Anumba
Bpandas
Cmatplotlib
Dscipy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing pandas instead of numba.
Trying to speed up code without any special library.
2fill in blank
medium

Complete the code to create a fast function using numba's decorator.

NumPy
@[1]
def fast_sum(arr):
    total = 0
    for x in arr:
        total += x
    return total
Drag options to blanks, or click blank then click option'
Ajit
Bnjit
Cvectorize
Dcompile
Attempts:
3 left
💡 Hint
Common Mistakes
Using @jit which is slower than @njit in some cases.
Using @vectorize which is for element-wise functions.
3fill in blank
hard

Fix the error in the code by completing the blank to convert a list to a NumPy array.

NumPy
import numpy as np

my_list = [1, 2, 3, 4]
my_array = np.[1](my_list)
print(my_array)
Drag options to blanks, or click blank then click option'
Aasarray
Blist
Carray
Dfromlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.list which does not exist.
Using np.fromlist which is not a valid NumPy function.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores squares of numbers greater than 3.

NumPy
squares = {x: x[1]2 for x in range(1, 6) if x [2] 3}
Drag options to blanks, or click blank then click option'
A**
B>
C<
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of ** for power.
Using < instead of > in the condition.
5fill in blank
hard

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

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 k.upper().
Using < instead of > in the condition.