code: def sample_entropy(x):
      
      x = np.array(x)
  
      sample_length = 1 # number of sequential points of the time series
      tolerance = 0.2 * np.std(x) # 0.2 is a common value for r - why?
  
      n = len(x)
      prev = np.zeros(n)
      curr = np.zeros(n)
      A = np.zeros((1, 1))  # number of matches for m = [1,...,template_length - 1]
      B = np.zeros((1, 1))  # number of matches for m = [1,...,template_length]
  
      for i in range(n - 1):
          nj = n - i - 1
          ts1 = x[i]
          for jj in range(nj):
              j = jj + i + 1
              if abs(x[j] - ts1) < tolerance:  # distance between two vectors
                  curr[jj] = prev[jj] + 1
                  temp_ts_length = min(sample_length, curr[jj])
                  for m in range(int(temp_ts_length)):
                      A[m] += 1
                      if j < n - 1:
                          B[m] += 1
              else:
                  curr[jj] = 0
          for j in range(nj):
              prev[j] = curr[j]
  
      N = n * (n - 1) / 2
      B = np.vstack(([N], B[0]))
  
      # sample entropy = -1 * (log (A/B))
      similarity_ratio = A / B
      se = -1 * np.log(similarity_ratio)
      se = np.reshape(se, -1)
      return se[0]
docs: Calculate and return sample entropy of x.
  
      .. rubric:: References
  
      |  [1] http://en.wikipedia.org/wiki/Sample_Entropy
      |  [2] https://www.ncbi.nlm.nih.gov/pubmed/10843903?dopt=Abstract
  
      :param x: the time series to calculate the feature of
      :type x: numpy.ndarray
  
      :return: the value of this feature
      :return type: float