Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the scipy.spatial.distance distance calculation function in python

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use the scipy.spatial.distance distance calculation function in python", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to use the scipy.spatial.distance distance calculation function in python.

1 scipy.spatialfrom scipy import spatial

The most important module in scipy.spatial should be the distance calculation module distance.

2 scipy.spatial.distance.cdist2.1 syntax scipy.spatial.distance.cdist (XA, XB, metric='euclidean', p=None, V=None, VI=None, w=None)

This function is used to calculate the distance between two input sets, and different distance measures are obtained by specifying different ways of calculating the distance through the metric parameter.

2.2 the value of metric

Braycurtis

Canberra

Chebyshev: Chebyshev distance

Cityblock

Correlation: correlation coefficient

Cosine: CoSine angle

Dice

Euclidean: Euclidean distance

Hamming: hamming distance

Jaccard: Jeckard similarity coefficient

Kulsinski

Mahalanobis: Mahalanobis distance

Matching

Minkowski: Minkowski distance

Rogerstanimoto

Russellrao

Seuclidean: standardized Euclidean distance

Sokalmichener

Sokalsneath

Sqeuclidean

Wminkowski

Yule

2.3 commonly used Euclidean distance calculation from scipy.spatial.distance import cdistimport numpy as npx1 = np.array ([(1p3), (2p4), (5pc6)]) x2 = [(3pc7), (4p8), (6pje 9)] cdist (x1mlmx2)) = result = array ([[4.47213595, 5.83095189, 7.81024968], [3.16227766, 4.47213595, 6.40312424], [2.23606798, 2.23606798, 3.16227766])

Analyze the above calculation process: the first row of data in the resulting array represents the distance between the first element point in the x1 array and each element point in the x2 array, and calculates the distance between the two points. Take the distance between the point (1) and (3) as an example:

Np.power ((1-3) * * 2 + (3-7) *) # = result = 4.4721359549995796 is all the contents of this article "how to use the scipy.spatial.distance distance calculation function in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report