code: def regularDTW(distMat, norm=True):
      
      sLen, tLen = distMat.shape
      totalDistance = zeros((sLen, tLen))
      totalDistance[0:sLen, 0:tLen] = distMat
  
      minDirection = zeros((sLen, tLen))
  
      for i in range(1, sLen):
          totalDistance[i, 0] = totalDistance[i, 0] + totalDistance[i - 1, 0]
  
      for j in range(1, tLen):
          totalDistance[0, j] = totalDistance[0, j] + totalDistance[0, j - 1]
  
      for i in range(1, sLen):
          for j in range(1, tLen):
              # direction,minPrevDistance = min(enumerate([totalDistance[i,j],totalDistance[i,j+1],totalDistance[i+1,j]]), key=operator.itemgetter(1))
              # totalDistance[i+1,j+1] = totalDistance[i+1,j+1] + minPrevDistance
              # minDirection[i,j] = direction
              minDirection[i, j], totalDistance[i, j] = min(
                  enumerate([totalDistance[i - 1, j - 1] + 2 * totalDistance[i, j],
                             totalDistance[i - 1, j] + totalDistance[i, j],
                             totalDistance[i, j - 1] + totalDistance[i, j]]), key=operator.itemgetter(1))
      if norm:
          return totalDistance[sLen - 1, tLen - 1] / (sLen + tLen)
      return totalDistance[sLen - 1, tLen - 1]
docs: Use a local distance matrix to perform dynamic time warping.
  
      Parameters
      ----------
      distMat : 2D array
          Local distance matrix.
  
      Returns
      -------
      float
          Total unweighted distance of the optimal path through the
          local distance matrix.