Complete the code to create a NumPy array from a list of numbers.
import numpy as np arr = np.[1]([1, 2, 3, 4, 5]) print(arr)
The array function creates a NumPy array from a Python list.
Complete the code to create an array of numbers from 0 to 9 using NumPy.
import numpy as np arr = np.[1](10) print(arr)
The arange function creates an array with evenly spaced values within a given range. Here, it creates numbers from 0 up to (but not including) 10.
Fix the error in the code to create 5 evenly spaced numbers between 0 and 1.
import numpy as np arr = np.linspace(0, 1, [1]) print(arr)
The third argument to linspace is the number of points to generate. To get 5 points between 0 and 1, use 5.
Fill both blanks to create an array of numbers from 2 to 10 (exclusive) with step size 2.
import numpy as np arr = np.arange([1], [2], 2) print(arr)
arange takes start, stop, and step arguments. To get numbers from 2 up to but not including 10 with step 2, use start=2 and stop=10.
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.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = [1]: [2] for word in words if len(word) [3] 3 print(lengths)
This is a dictionary comprehension. It creates a dictionary where each key is a word and the value is its length, but only includes words longer than 3 characters.