def regularDTW(distMat, norm=True):
sLen, tLen = distMat.shape<EOL>totalDistance = zeros((sLen, tLen))<EOL>totalDistance[<NUM_LIT:0>:sLen, <NUM_LIT:0>:tLen] = distMat<EOL>minDirection = zeros((sLen, tLen))<EOL>for i in range(<NUM_LIT:1>, sLen):<EOL><INDENT>totalDistance[i, <NUM_LIT:0>] = totalDistance[i, <NUM_LIT:0>] + totalDistance[i - <NUM_LIT:1>, <NUM_LIT:0>]<EOL><DEDENT>for j in range(<NUM_LIT:1>, tLen):<EOL><INDENT>totalDistance[<NUM_LIT:0>, j] = totalDistance[<NUM_LIT:0>, j] + totalDistance[<NUM_LIT:0>, j - <NUM_LIT:1>]<EOL><DEDENT>for i in range(<NUM_LIT:1>, sLen):<EOL><INDENT>for j in range(<NUM_LIT:1>, tLen):<EOL><INDENT>minDirection[i, j], totalDistance[i, j] = min(<EOL>enumerate([totalDistance[i - <NUM_LIT:1>, j - <NUM_LIT:1>] + <NUM_LIT:2> * totalDistance[i, j],<EOL>totalDistance[i - <NUM_LIT:1>, j] + totalDistance[i, j],<EOL>totalDistance[i, j - <NUM_LIT:1>] + totalDistance[i, j]]), key=operator.itemgetter(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>if norm:<EOL><INDENT>return totalDistance[sLen - <NUM_LIT:1>, tLen - <NUM_LIT:1>] / (sLen + tLen)<EOL><DEDENT>return totalDistance[sLen - <NUM_LIT:1>, tLen - <NUM_LIT:1>]<EOL>
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.