from scipy.spatial import distance Y = distance.pdist(m1, 'cosine') z=distance.squareform(Y) cosine 是参数,可以指定别的距离计算法方式