Complete the code to check which elements of array1 are in array2 using np.in1d().
import numpy as np array1 = np.array([1, 2, 3, 4]) array2 = np.array([3, 4, 5, 6]) result = np.in1d(array1, [1]) print(result)
The second argument of np.in1d() is the array to check membership against. Here, array2 is correct.
Complete the code to get a boolean array showing membership of elements in arr1 within arr2.
import numpy as np arr1 = np.array(['apple', 'banana', 'cherry']) arr2 = np.array(['banana', 'date', 'fig']) membership = np.in1d(arr1, [1]) print(membership)
The second argument is the array to check membership against. Here, arr2 is correct.
Fix the error in the code to correctly test membership using np.in1d().
import numpy as np x = np.array([10, 20, 30]) y = np.array([20, 40, 60]) result = np.in1d([1], y) print(result)
The first argument should be the array whose elements you want to test for membership in the second array. Here, x is correct.
Fill both blanks to create a dictionary showing elements of words and whether their length is greater than 5 and if they are in the list check_list using np.in1d().
words = ['apple', 'banana', 'cherry', 'date'] check_list = ['banana', 'date', 'fig'] result = {word: (len(word) [1] 5 and np.in1d([word], [2])[0]) for word in words} print(result)
The condition checks if the length of the word is greater than 5 and if the word is in check_list. So, > and check_list are correct.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their membership boolean in check_words if their length is less than 6.
words = ['apple', 'banana', 'cherry', 'date'] check_words = ['APPLE', 'DATE', 'FIG'] result = {word[1]: np.in1d([word[2]], [3])[0] for word in words if len(word) < 6} print(result)
The keys are uppercase words, so .upper() is used twice. Membership is checked against check_words.