code: def _k(
      weights, k=0, clip=False, norm=False, eps=15
  ):  # XXX: better 9 ?
      "trim weights at k%; if clip is True, winsorize instead of trim"
      # NOTE: eps is tolerance for cancellation of similar values
      import numpy as np
  
      try:
          klo, khi = k
      except TypeError:
          klo = khi = k
      if klo + khi > 100:
          msg = "cannot crop '%s + %s > 100' percent" % (klo, khi)
          raise ValueError(msg)
      elif klo < 0 or khi < 0:
          msg = "cannot crop negative percent '%s + %s'" % (klo, khi)
          raise ValueError(msg)
      else:
          klo, khi = 0.01 * klo, 0.01 * khi
      w = np.array(weights, dtype=float) / sum(
          weights
      )  # XXX: no dtype?
      w_lo, w_hi = np.cumsum(w), np.cumsum(w[::-1])
      # calculate the cropped indices
      lo = len(w) - sum((w_lo - klo).round(eps) > 0)
      hi = sum((w_hi - khi).round(eps) > 0) - 1
      # flip indices if flipped
      if lo > hi:
          lo, hi = hi, lo
      if not clip:
          # find the values at k%
          w_lo = w_lo[lo]
          w_hi = w_hi[len(w) - 1 - hi]
          # reset the values at k%
          if klo + khi == 1:
              w[lo] = w[hi] = 0
          elif lo == hi:
              w[lo] = max(1 - khi - klo, 0)
          else:
              w[lo] = max(w_lo - klo, 0)
              w[hi] = max(w_hi - khi, 0)
      else:
          # reset the values at k%
          if lo == hi:
              w[lo] = sum(w)
          else:
              w[lo] += sum(w[:lo])
              w[hi] += sum(w[hi + 1 :])
      # trim the remaining weights
      w[:lo] = 0
      w[hi + 1 :] = 0
      if not norm:
          w *= sum(weights)
      return w.tolist()
  
imports: from mystic.math.stats import *
  from mystic.math.samples import *
  from mystic.math.integrate import *
  from mystic.symbolic import generate_solvers, generate_constraint, solve
  from mystic.symbolic import generate_conditions, generate_penalty
  from mystic.math import almostEqual
  from mystic.math.distance import Lnorm
  from numpy import asarray
label_desc: Use image node_id 43 for calling a global function with example usage: _k(weights, k, clip, norm, eps) and returns: w