code: def med_filt(x, k=201):
      
      if x.ndim > 1:
          x = np.squeeze(x)
      med = np.median(x)
      assert k % 2 == 1, "Median filter length must be odd."
      assert x.ndim == 1, "Input must be one-dimensional."
      k2 = (k - 1) // 2
      y = np.zeros((len(x), k), dtype=x.dtype)
      y[:, k2] = x
      for i in range(k2):
          j = k2 - i
          y[j:, i] = x[:-j]
          y[:j, i] = x[0]
          y[:-j, -(i + 1)] = x[j:]
          y[-j:, -(i + 1)] = med
      return np.median(y, axis=1)
docs: Apply a length-k median filter to a 1D array x.
      Boundaries are extended by repeating endpoints.