Complete the code to find the common elements between two arrays using numpy.
import numpy as np arr1 = np.array([1, 2, 3, 4]) arr2 = np.array([3, 4, 5, 6]) common = np.[1](arr1, arr2) print(common)
The np.intersect1d() function returns the sorted, unique values that are in both input arrays.
Complete the code to find the intersection of two lists converted to numpy arrays.
import numpy as np list1 = [10, 20, 30, 40] list2 = [30, 40, 50, 60] arr1 = np.array(list1) arr2 = np.array(list2) result = np.intersect1d(arr1, [1]) print(result)
The intersection function requires two numpy arrays as input. Here, arr2 is the second numpy array.
Fix the error in the code to correctly find the intersection of two arrays.
import numpy as np arr1 = np.array([7, 8, 9]) arr2 = np.array([8, 9, 10]) common = np.intersect1d(arr1, arr2[1]) print(common)
The function call was missing the closing parenthesis. Adding ) fixes the syntax error.
Fill both blanks to create a dictionary with words as keys and their lengths only if length is greater than 3.
words = ['data', 'science', 'ai', 'ml'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension uses len(word) as the value and filters words where length is greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values only for items with values greater than 0.
data = {'a': 1, 'b': -1, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
print(result)The dictionary comprehension uses uppercase keys with k.upper(), values v, and filters items where value is greater than 0.