SciPy KDTree 距离单位? [英] SciPy KDTree distance units?

查看:57
本文介绍了SciPy KDTree 距离单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有数组,其中第 1 列以英尺为单位,第 2 列以英尺为单位,第 3 列以秒为单位.例如:

Let's say I have and array, where column 1 is in feet, column 2 is in feet, and column 3 is in seconds. For example:

x = [50 40 30]

然后我有另一个数组,y,具有相同的单位和相同的列数,但有很多行.然后我用 Scipy 把它变成一个 KDTree:

I then have another array, y, with the same units and same number of columns, but many rows. I then turn it into a KDTree with Scipy:

tree = scipy.KDTree(y)

然后查询那棵树:

distance,index = tree.query(x,k=1)

默认情况下,我相信距离是根据欧几里得范数计算的.

By default, I believe the distance is calculated based on the Euclidean norm.

例如,distance 可能是:

print distance
[34]

这些是什么单位?他们是否仍然在原来的脚,脚,&秒?

What units are these? Are they still in the original feet, feet, & seconds?

推荐答案

当测量值是单位无法相互转换的事物(例如时间和距离)时,它不会返回任何可解释的单位.它返回 sqrt(feet**2 + feet**2 + sec**2),它不是一个度量单位.这是欧几里得范数,但在这种情况下是在一个抽象空间上.

It doesn't return any interpretable unit when the measurements are of things in which units can't be converted to each other (time and distance, for example). It's returning sqrt(feet**2 + feet**2 + sec**2), which is not a unit of measure. It's the Euclidean norm, but over an abstract space in this case.

顺便说一下,这不是一个真正的 Python 问题.scipy 只是操纵你给它的数字,不知道单位.这更像是一个如何解释数学的问题,例如,如果你想把一个 5' x 5' 的盒子比一个 6' x 6' 的盒子更接近"一个 7' x 7' 的盒子,因为你碰巧在几秒钟内测量它们,并在几小时后测量第三个盒子.只有您知道您的数据以及哪些特征对于构建相似度评分真正重要.在我刚刚给出的情况下,这是没有意义的.如果您根据体型和最佳 100 米时间对短跑运动员的相似性进行排名,那么这可能是有道理的.

This isn't really a Python question, by the way. scipy is just manipulating the numbers you give it and doesn't know the units. It's more a question of how to interpret math, for instance, if you want to think of a 5' x 5' box as 'closer' to a 7' x 7' box than a 6' x 6' box because you happened to measure them within seconds of each other and measured the third box hours later. Only you know your data and what features really count for building a similarity score. In the case I just gave, it doesn't make sense. If you're ranking similarity of sprinters based on both body size and best 100m time, then it probably makes sense.

这篇关于SciPy KDTree 距离单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆