Complete the code to find elements in array1 that are not in array2 using np.setdiff1d().
import numpy as np array1 = np.array([1, 2, 3, 4, 5]) array2 = np.array([3, 4, 6]) difference = np.[1](array1, array2) print(difference)
The np.setdiff1d() function returns the sorted, unique values in the first array that are not in the second array.
Complete the code to find the difference between two arrays and store it in 'diff'.
import numpy as np arr1 = np.array([10, 20, 30, 40]) arr2 = np.array([20, 50]) diff = np.[1](arr1, arr2) print(diff)
np.setdiff1d(arr1, arr2) returns elements in arr1 that are not in arr2.
Fix the error in the code to correctly find the difference between arrays using np.setdiff1d().
import numpy as np x = np.array([5, 6, 7, 8]) y = np.array([7, 9]) diff = np.setdiff1d(x, [1]) print(diff)
The second argument to np.setdiff1d() should be the array to compare against, which is y here.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary of words and their lengths, but only include words with length greater than 3.
words = ['sun', 'moon', 'star', 'sky'] lengths = { [1]: [2] for w in words if len(w) [3] 3} print(lengths)
The dictionary keys are the words themselves (w), values are their lengths (len(w)), and the condition filters words longer than 3 characters (> 3).