Complete the code to create a 2x2 matrix using NumPy.
import numpy as np matrix = np.array([1])
The correct way to create a 2x2 matrix is by passing a list of lists representing rows.
Complete the code to compute the dot product of two vectors using NumPy.
import numpy as np v1 = np.array([1, 2, 3]) v2 = np.array([4, 5, 6]) dot_product = np.[1](v1, v2)
multiply which returns element-wise multiplication.cross which computes the cross product.The np.dot function computes the dot product of two vectors.
Fix the error in the code to compute the inverse of a matrix using SciPy.
from scipy import linalg import numpy as np matrix = np.array([[1, 2], [3, 4]]) inverse = linalg.[1](matrix)
inverse or invert.The correct SciPy function to compute the inverse of a matrix is linalg.inv.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps each uppercase word to its length only if the length is greater than 2.
words = ['AI', 'ML', 'Data', 'Code'] result = { [1]: [2] for word in words if [3] }
word.lower() instead of uppercase.The comprehension maps each word converted to uppercase (word.upper()) to its length (len(word)) only if the length is greater than 2 (len(word) > 2).