code: def box_filter(array, n_iqr=1.5, return_index=False):
      
      if not isinstance(array, np.ndarray):
          array = np.array(array)
      Q3 = np.percentile(array, 75)
      Q1 = np.percentile(array, 25)
      IQR = Q3 - Q1
      lower, upper = Q1 - n_iqr * IQR, Q3 + n_iqr * IQR
  
      good_index = np.where(np.logical_and(array >= lower, array <= upper))
      bad_index = np.where(np.logical_or(array < lower, array > upper))
  
      if return_index:
          return good_index[0], bad_index[0]
      else:
          return array[good_index], array[bad_index]
docs: Box plot outlier detector.
  
      :param array: array of data.
      :param n_std: default 1.5, exclude data out of ``n_iqr`` IQR.
      :param return_index: boolean, default False, if True, only returns index.