In NumPy, the masked_outside() function is used to mask an array outside a given interval.
ma.masked_outside(x, v1, v2)
This function takes the following parameter values:
x: This is the input array.v1 and v2 : These represent the boundary for which the values of the given array are not to be masked. Both values—v1 and v2—are not included when masking.This function returns a masked array with values within the specified intervals masked.
# A code to illustrate the masked_inside() function# importing the necessary librariesimport numpy as npimport numpy.ma as ma# creating an input arraymy_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])# masking the values outside 3 to 7mask_array =ma.masked_outside(my_array, 3, 7)print(mask_array)
my_array.3–7 in the input array using the masked_outside() function. The result is assigned to a variable, mask_array.mask_array.