Complete the code to create a masked array from a numpy array.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) masked_arr = np.ma.[1](arr)
The np.ma.masked_array() function creates a masked array from a regular numpy array.
Complete the code to mask all elements equal to 3 in the array.
import numpy as np arr = np.array([1, 2, 3, 4, 3]) masked_arr = np.ma.masked_array(arr, mask=arr [1] 3)
The mask should be True where elements equal 3, so use arr == 3.
Fix the error in the code to correctly mask elements less than 0.
import numpy as np arr = np.array([-1, 0, 1, 2]) masked_arr = np.ma.masked_array(arr, mask=arr [1] 0)
To mask elements less than 0, use the less than operator <.
Fill both blanks to create a masked array masking values greater than 10 and then fill masked values with -1.
import numpy as np arr = np.array([5, 12, 7, 15, 3]) masked_arr = np.ma.masked_array(arr, mask=arr [1] 10) filled_arr = masked_arr.[2](-1)
Mask elements greater than 10 using arr > 10. Use filled(-1) to replace masked values with -1.
Fill all three blanks to create a masked array from a list, mask negative values, and get the compressed (unmasked) data.
import numpy as np lst = [4, -2, 7, -5, 9] masked_arr = np.ma.[1](lst, mask=[x [2] 0 for x in lst]) compressed_data = masked_arr.[3]()
Create a masked array with np.ma.masked_array(). Mask negative values using x < 0. Use compressed() to get unmasked data.