0
0
SciPydata~10 mins

NumPy array foundation review in SciPy - Interactive Code Practice

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

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

SciPy
import numpy as np
arr = np.[1]([1, 2, 3, 4])
Drag options to blanks, or click blank then click option'
Arange
Blist
Cmatrix
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.list instead of np.array
Trying to use np.range which creates sequences, not arrays
2fill in blank
medium

Complete the code to find the shape of a NumPy array.

SciPy
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
shape = arr.[1]
Drag options to blanks, or click blank then click option'
Ashape
Blen
Cdim
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using size which returns total elements, not shape
Trying to call len() which only returns the first dimension
3fill in blank
hard

Fix the error in the code to correctly create a 2D NumPy array filled with zeros.

SciPy
import numpy as np
arr = np.zeros([1])
Drag options to blanks, or click blank then click option'
A5
B(5, 5)
C[5]
D5, 5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single integer instead of a tuple
Passing a list instead of a tuple
Passing two separate arguments instead of a tuple
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.

SciPy
words = ['apple', 'bat', 'cat', 'doggy']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dlen(word) < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length
Using the wrong condition like less than 3
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 2.

SciPy
words = ['hi', 'hello', 'hey']
result = { [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 2
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of uppercase
Not filtering words by length
Mapping words instead of their lengths