How to get flat clustering corresponding to color clusters in the dendrogram created by scipy

I think you’re on the right track. Let’s try this: import scipy import scipy.cluster.hierarchy as sch X = scipy.randn(100, 2) # 100 2-dimensional observations d = sch.distance.pdist(X) # vector of (100 choose 2) pairwise distances L = sch.linkage(d, method=’complete’) ind = sch.fcluster(L, 0.5*d.max(), ‘distance’) ind will give you cluster indices for each of the 100 … Read more

Speedup scipy griddata for multiple interpolations between two irregular grids

There are several things going on every time you make a call to scipy.interpolate.griddata: First, a call to sp.spatial.qhull.Delaunay is made to triangulate the irregular grid coordinates. Then, for each point in the new grid, the triangulation is searched to find in which triangle (actually, in which simplex, which in your 3D case will be … Read more

Bézier curve fitting with SciPy

Here’s a way to do Bezier curves with numpy: import numpy as np from scipy.special import comb def bernstein_poly(i, n, t): “”” The Bernstein polynomial of n, i as a function of t “”” return comb(n, i) * ( t**(n-i) ) * (1 – t)**i def bezier_curve(points, nTimes=1000): “”” Given a set of control points, … Read more