0
0
Data Analysis Pythondata~10 mins

Array creation (array, arange, linspace) in Data Analysis Python - 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 list of numbers.

Data Analysis Python
import numpy as np
arr = np.[1]([1, 2, 3, 4, 5])
print(arr)
Drag options to blanks, or click blank then click option'
Aarray
Barange
Clinspace
Dzeros
Attempts:
3 left
💡 Hint
Common Mistakes
Using arange or linspace instead of array when starting from a list.
Forgetting to import numpy as np.
2fill in blank
medium

Complete the code to create an array of numbers from 0 to 9 using NumPy.

Data Analysis Python
import numpy as np
arr = np.[1](10)
print(arr)
Drag options to blanks, or click blank then click option'
Aarange
Barray
Clinspace
Dzeros
Attempts:
3 left
💡 Hint
Common Mistakes
Using array with a single integer argument instead of arange.
Using linspace which requires start and stop arguments.
3fill in blank
hard

Fix the error in the code to create 5 evenly spaced numbers between 0 and 1.

Data Analysis Python
import numpy as np
arr = np.linspace(0, 1, [1])
print(arr)
Drag options to blanks, or click blank then click option'
A10
B0
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 which results in too few points.
Using 10 which creates more points than needed.
4fill in blank
hard

Fill both blanks to create an array of numbers from 2 to 10 (exclusive) with step size 2.

Data Analysis Python
import numpy as np
arr = np.arange([1], [2], 2)
print(arr)
Drag options to blanks, or click blank then click option'
A2
B10
C12
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using 12 as stop which includes extra numbers.
Using 8 as stop which excludes 8 itself.
5fill in blank
hard

Fill all three blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.

Data Analysis Python
words = ['apple', 'bat', 'carrot', 'dog']
lengths = [1]: [2] for word in words if len(word) [3] 3
print(lengths)
Drag options to blanks, or click blank then click option'
A{word
Blen(word)
C>
D{word: len(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Not using braces to create a dictionary.
Using '<' instead of '>' in the condition.
Not using len(word) for the value.