[英]python dataframe of Euclidean distance
I have the following Pandas DataFrame:我有以下 Pandas DataFrame:
x1 y1 z1 s1 x2 y2 z2 s2 x3 y3 z3 s3 x4 y4 z4 s4 xto yto zto
1 1 1 1 1 4 5 7 11 17 89 34 1 1 1 1 1 1 1
4 4 4 1 4 5 7 10 17 79 34 31 51 51 19 10 61 21 20
4 4 4 1 4 5 7 10 17 79 34 31 51 51 19 10 61 21 20
4 4 4 1 4 5 7 10 17 79 34 31 51 51 19 10 61 21 20
I need please the euclidean distance also:我还需要欧几里得距离:
d1 = sqr(x1-xto)^2+(y1-yt0)^2+(z1-zto)^2
d2 = sqr(x2-xto)^2+(y2-yt0)^2+(z2-zto)^2
d3 = sqr(x3-xto)^2+(y3-yt0)^2+(z3-zto)^2
d4 = sqr(x4-xto)^2+(y4-yt0)^2+(z4-zto)^2
to get a new dataframe.得到一个新的 dataframe。 something like this:
像这样的东西:
d1 s1 d2 s2 d3 s3 d4 s4
02 31 41 52 63 54 55 85
02 71 81 52 63 54 55 85
02 51 41 52 63 54 55 85
02 31 41 52 63 54 55 85
Try the SciPy Library , there is a method for calculating the Euclidean distance.试试SciPy Library ,有一种计算欧几里得距离的方法。 The argument for the method is array like so you should be able to feed in columns from a pd.df
该方法的参数是数组,因此您应该能够从 pd.df 中输入列
You can then make list of distances and put them in a dataframe然后,您可以列出距离并将它们放入 dataframe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.