Python Scipy Tutorials:Distance between points

来源:互联网 发布:手机号码人肉搜索软件 编辑:程序博客网 时间:2024/06/02 02:44
# -*- coding: utf-8 -*-"""Python Version: 3.5Created on Fri May 12 13:52:52 2017E-mail: Eric2014_Lv@sjtu.edu.cn@author: DidiLv"""import numpy as npfrom scipy.spatial.distance import pdist, squareform# Create the following array where each row is a point in 2D space:# [[0 1]#  [1 0]#  [2 0]]x = np.array([[0, 1], [1, 0], [2, 0]])print(x)# Compute the Euclidean distance between all rows of x.# d[i, j] is the Euclidean distance between x[i, :] and x[j, :],# and d is the following array:# [[ 0.          1.41421356  2.23606798]#  [ 1.41421356  0.          1.        ]#  [ 2.23606798  1.          0.        ]]d = squareform(pdist(x, 'euclidean'))#d = pdist(x, 'euclidean')print(d)
0 0
原创粉丝点击