code: def stratified_resample(weights):
      """Performs the stratified resampling algorithm used by particle filters.
  
      This algorithms aims to make selections relatively uniformly across the
      particles. It divides the cumulative sum of the weights into N equal
      divisions, and then selects one particle randomly from each division. This
      guarantees that each sample is between 0 and 2/N apart.
  
      Parameters
      ----------
      weights : list-like of float
          list of weights as floats
  
      Returns
      -------
  
      indexes : ndarray of ints
          array of indexes into the weights defining the resample. i.e. the
          index of the zeroth resample is indexes[0], etc.
      """
  
      N = len(weights)
      # make N subdivisions, and chose a random position within each one
      positions = (random(N) + range(N)) / N
  
      indexes = np.zeros(N, "i")
      cumulative_sum = np.cumsum(weights)
      i, j = 0, 0
      while i < N:
          if positions[i] < cumulative_sum[j]:
              indexes[i] = j
              i += 1
          else:
              j += 1
      return indexes
  
imports: import numpy
  from numpy.random import random
label_desc: Use image node_id 2 for calling a global function with example usage: stratified_resample(weights) and returns: indexes