scipy linkage:Distance matrix ‘X’ must be symmetric

Published on:
Last updated:

This post is also available in: 日本語 (Japanese)

This is a note about how to solve "Distance matrix 'X' must be symmetric" when create dendrogram by using scipy.cluster.hierarchy.linkage .

Distance matrix 'X' must be symmetric

At first, checked the .shape of matrix 'X' so that matrix 'X' is symmetric.

Then, because it is a distance matrix, it should be finite number.
In my case, the error occured because it contains infs.

All elements of the condensed distance matrix must be finite, i.e. no NaNs or infs.

Kuniyoshi Takemoto is the founder of LLC, and editor of this blog( more and follow me on LinkedIn.