Complete the code to create a 2x2 matrix using numpy.
import numpy as np matrix = np.array([1]) print(matrix)
The correct way to create a 2x2 matrix is by passing a list of lists representing rows.
Complete the code to calculate 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) print(dot_product)
multiply which returns element-wise product.cross which calculates cross product, not dot product.The np.dot function calculates the dot product of two vectors.
Fix the error in the code to compute the inverse of a matrix using numpy.
import numpy as np matrix = np.array([[1, 2], [3, 4]]) inverse = np.linalg.[1](matrix) print(inverse)
The correct numpy function to compute matrix inverse is np.linalg.inv.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = { [1] : len([2]) for [1] in words if len([1]) > 3 } print(lengths)
We use the variable 'word' to iterate over 'words' and map each word to its length if length > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.
words = ['AI', 'ML', 'Data', 'Code'] result = { [1] : [2] for [3] in words if len([3]) > 2 } print(result)
upper() to the key.The comprehension uses 'word' as the loop variable, maps word.upper() to len(word) if length > 2.