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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -