Complete the code to create a NumPy array from a Python list.
import numpy as np arr = np.[1]([1, 2, 3, 4])
Use np.array to convert a Python list into a NumPy array for vectorized operations.
Complete the code to compute the element-wise square of a NumPy array.
import numpy as np arr = np.array([1, 2, 3]) squared = arr[1]2
The ** operator raises each element to the power given, here squaring each element.
Fix the error in the code to compute the dot product of two arrays using SciPy.
from scipy import [1] import numpy as np arr1 = np.array([1, 2]) arr2 = np.array([3, 4]) dot_product = [1].dot(arr1, arr2)
The dot function is in the scipy.linalg module for linear algebra operations.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'ai', 'science', 'ml'] lengths = {word: [1] for word in words if [2]
len(word) for length calculation.The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 2.
words = ['cat', 'to', 'dog', 'a'] result = { [1]: [2] for word in words if [3] }
word.lower() instead of uppercase.The comprehension maps each word in uppercase to its length, filtering only words longer than 2 characters.