Skip to content

Instantly share code, notes, and snippets.

@kaizu
Created June 19, 2014 12:36
Show Gist options
  • Save kaizu/2bcc06a4ac7dad1c4c39 to your computer and use it in GitHub Desktop.
Save kaizu/2bcc06a4ac7dad1c4c39 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import numpy
data = []
x = numpy.linspace(0.0, 10.0, 100)
data.extend([numpy.sin(x) + numpy.random.uniform(-0.5, 0.5, 100) for _ in range(5)])
data.extend([numpy.cos(x) + numpy.random.uniform(-0.5, 0.5, 100) for _ in range(5)])
numpy.random.shuffle(data)
import matplotlib.pylab as pylab
plt.matshow(numpy.asarray(data), aspect='auto', origin='lower', cmap='hot')
plt.show()
from scipy.spatial.distance import pdist, squareform
from scipy.cluster.hierarchy import linkage, dendrogram
dist = squareform(pdist(data, metric='euclidean'))
dend = dendrogram(linkage(dist, method='complete'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment