0
0
NumPydata~10 mins

Generalized ufuncs concept 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 import the numpy module with its common alias.

NumPy
import [1] as np
Drag options to blanks, or click blank then click option'
Anum
Bnumpy
Cnump
Dnp
Attempts:
3 left
💡 Hint
Common Mistakes
Using the alias name instead of the full library name in the import statement.
Misspelling the library name.
2fill in blank
medium

Complete the code to create a numpy array from a Python list.

NumPy
arr = np.[1]([1, 2, 3, 4])
Drag options to blanks, or click blank then click option'
Alist
Basarray
Carray
Dfromlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list instead of array.
Using asarray which also works but is less common for direct creation.
3fill in blank
hard

Fix the error in the code to apply a generalized ufunc that adds 1 to each element.

NumPy
result = np.add(arr, [1])
Drag options to blanks, or click blank then click option'
Aarr
Bnp.array(1)
C[1]
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the array itself as the second argument.
Passing a list or numpy array instead of a scalar.
4fill in blank
hard

Fill both blanks to create a generalized ufunc that multiplies each element by 2 and then adds 3.

NumPy
step1 = np.multiply(arr, [1])
result = np.add(step1, [2])
Drag options to blanks, or click blank then click option'
A2
B3
Carr
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the array instead of scalar values.
Mixing up the order of operations.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.

NumPy
lengths = { [1]: [2] for [1] in words if [2] [3] 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length as the key instead of the word.
Using the wrong comparison operator.