Complete the code to find the union of two arrays using numpy.
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([3, 4, 5]) result = np.[1](arr1, arr2) print(result)
The np.union1d() function returns the sorted unique values that are in either of the two input arrays, effectively giving their union.
Complete the code to find the union of two numpy arrays and store it in 'union_result'.
import numpy as np array_a = np.array([10, 20, 30]) array_b = np.array([20, 40, 50]) union_result = np.[1](array_a, array_b) print(union_result)
np.union1d() returns the sorted unique elements from both arrays combined, which is the union.
Fix the error in the code to correctly compute the union of two numpy arrays.
import numpy as np x = np.array([1, 3, 5]) y = np.array([2, 3, 4]) union = np.[1](x, y) print(union)
The correct function name is union1d all lowercase. Other options are invalid function names and cause errors.
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', 'ai', 'ml'] 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 uppercase words to their lengths only if length is greater than 2.
words = ['go', 'run', 'jump', 'fly'] result = [1] = { [2]: [3] for w in words if len(w) > 2 }
The dictionary named word_dict maps each uppercase word w.upper() to its length len(w), filtering words longer than 2 characters.