docs: def OrderReplicates(replicates, K):
  
      ''' Inputs: An array of replicates, and the size of the data.
  
          Outputs: a Nxdims arrary of the data in the replicates, normalized by the standard deviation
  
      '''
  
      dims = np.shape(replicates[0]['destimated'])
  
      sigma = replicates[0]['destimated']
      zerosigma = (sigma == 0)
      sigmacorr = zerosigma  # we need to avoid errors with zero standard errors.  We will ignore them later.
      sigma += sigmacorr
  
      yi = []
      for (replicate_index, replicate) in enumerate(replicates):
          yi.append(replicate['error']/sigma)
      yiarray = np.asarray(yi)
      sortedyi = np.zeros(np.shape(yiarray))
      if len(dims) == 0:
          sortedyi[:] = np.sort(yiarray)
      elif len(dims) == 1:
          for i in range(K):
              sortedyi[:,i] = np.sort(yiarray[:,i])
      elif len(dims) == 2:
          for i in range(K):
              for j in range(K):
                  sortedyi[:,i,j] = np.sort(yiarray[:,i,j])
  
      # remove the correction so we have zero sigmas again
      sigma -= sigmacorr
      return sortedyi