Complete the code to clip the values in the array to a minimum of 0.
import numpy as np arr = np.array([-5, 0, 5, 10]) clipped = np.clip(arr, [1], None) print(clipped)
np.clip() limits values below the minimum to the minimum value. Here, minimum is 0.
Complete the code to clip the values in the array between 2 and 8.
import numpy as np arr = np.array([1, 3, 5, 9]) clipped = np.clip(arr, [1], 8) print(clipped)
Setting minimum to 2 and maximum to 8 clips values below 2 to 2 and above 8 to 8.
Fix the error in the code to clip values between 1 and 4.
import numpy as np arr = np.array([0, 2, 5, 7]) clipped = np.clip(arr, 1, [1]) print(clipped)
The maximum bound should be 4 to clip values above 4 down to 4.
Fill both blanks to clip values below 10 to 10 and above 20 to 20.
import numpy as np arr = np.array([5, 10, 15, 25]) clipped = np.clip(arr, [1], [2]) print(clipped)
Minimum is 10 and maximum is 20 to clip values outside this range.
Fill all three blanks to create a dictionary with words as keys and their lengths clipped to max 4.
words = ['apple', 'bat', 'cat', 'dolphin'] lengths = {word: len(word) if len(word) < [1] else [2] for word in words if len(word) > [3] print(lengths)
Clip lengths to max 4: if length less than 4, keep it; else set to 4. Include words longer than 3.
