python - Faster way of calculating a distance matrix with numpy? -
i calculating matrix numpy/scipy this:
cost = np.empty([chroma1.data.shape[1], chroma2.data.shape[1]]) x, cx in enumerate(chroma1.transpose()): y, cy in enumerate(chroma2.transpose()): cost[x, y] = sp.distance.euclidean(cx, cy)
this takes quite amount of time. there numpy/scipy function allow me rid of 2 nested loops?
it looks you're calculating distance matrix. scipy.spatial.distance
contains several specialized, optimized functions doing that.
in case:
cost = scipy.spatial.distance.cdist(chroma1.t, chroma2.t)
should want.
Comments
Post a Comment