Skip to content
DTW (Dynamic Time Warping) python module
Branch: master
Clone or download

Latest commit

Latest commit 6c080af Dec 11, 2019


Type Name Latest commit message Commit time
Failed to load latest commit information.
dtw Update version to 1.4.0 Oct 29, 2019
examples Update speech-rec example with tensorflow dataset. Jul 22, 2019
tests Remove unusual distance normalisation. Jul 22, 2019
.gitignore travis May 7, 2017
.travis.yml Improve overall project maintainability. (#32) Jan 11, 2019
LICENSE Initial commit Jul 28, 2014 Fix distance name in README Dec 8, 2019
acc.png Update readme and example. Jan 11, 2019
setup.cfg Improve overall project maintainability. (#32) Jan 11, 2019 Update long description for pypi. Jan 11, 2019

Dynamic Time Warping Python Module

Build Status

Dynamic time warping is used as a similarity measured between temporal sequences. This package provides two implementations:

import numpy as np

# We define two sequences x, y as numpy array
# where y is actually a sub-sequence from x
x = np.array([2, 0, 1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)
y = np.array([1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)

from dtw import dtw

manhattan_distance = lambda x, y: np.abs(x - y)

d, cost_matrix, acc_cost_matrix, path = dtw(x, y, dist=manhattan_distance)

>>> 2.0 # Only the cost for the insertions is kept

# You can also visualise the accumulated cost and the shortest path
import matplotlib.pyplot as plt

plt.imshow(acc_cost_matrix.T, origin='lower', cmap='gray', interpolation='nearest')
plt.plot(path[0], path[1], 'w')

Result of the accumulated cost matrix and the shortest path (in white) found: Acc cost matrix and shortest path

Other examples are available as notebook


python -m pip install dtw

It is tested on Python 2.7, 3.4, 3.5 and 3.6. It requires numpy and scipy.

You can’t perform that action at this time.