Complete the code to shuffle the array in-place using NumPy.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) np.random.[1](arr) print(arr)
The np.random.shuffle() function shuffles the array in-place, changing the order of elements randomly.
Complete the code to create a shuffled copy of the array without changing the original.
import numpy as np arr = np.array([10, 20, 30, 40, 50]) shuffled_arr = np.random.[1](arr) print(shuffled_arr) print(arr)
The np.random.permutation() function returns a new shuffled array, leaving the original unchanged.
Fix the error in the code to shuffle the array in-place.
import numpy as np arr = np.array([5, 6, 7, 8]) np.random.[1](arr) print(arr)
np.random.shuffle() shuffles the array in-place and does not take a size argument. The other functions either return new arrays or do not exist.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 letters.
words = ['pear', 'fig', 'grape', 'kiwi'] result = { [1]: [2] for w in words if [3] } print(result)
The dictionary comprehension uses w.upper() as keys, len(w) as values, and filters words with length greater than 3.