Complete the code to import the NumPy library with its common alias.
import [1] as np
NumPy is imported using the name numpy. The common alias is np.
Complete the code to create a NumPy array from a Python list.
arr = np.[1]([1, 2, 3, 4])
list instead of array.series which is from pandas.matrix which is different from array.The function np.array() converts a Python list into a NumPy array.
Fix the error in the code to calculate the mean of a NumPy array.
mean_value = arr.[1]()average() as a method on the array.median() which returns the middle value, not the mean.mode() which is not a NumPy array method.The correct method to calculate the average value of a NumPy array is mean().
Fill both blanks to create a dictionary comprehension that maps each number to its square if the number is even.
squares = {x: x[1]2 for x in range(1, 6) if x [2] 2 == 0}+ instead of exponentiation.// which is floor division, not modulus.== incorrectly without modulus.The operator ** is used for exponentiation (square), and % checks if a number is even by remainder 0.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to the original words if the length is greater than 3.
result = { [1]: [2] for word in words if len(word) [3] 3 }len(word) as the key instead of uppercase word.< instead of > in the condition.The key is the uppercase word (word.upper()), the value is the original word (word), and the condition checks if length is greater than 3 (>).