如何找到另一个列表中最相似的子列表?蟒蛇 [英] How to find the most similar sub list of another list? Python

查看:72
本文介绍了如何找到另一个列表中最相似的子列表?蟒蛇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有60个子列表的列表。每个子列表有30个子子列表。每个子子列表看起来像[x,y]对于每个子子列表,如何找到下一个子列表中最近的子子列表?



例如,我在子列表[0],子子列表[0]中。现在我转到子列表[1]并搜索具有最接近的x,y坐标的子子列表。



这是一个例子我想完成:

 input = [[[99,87],[400,500],[300,95]],
[ [297,107],[100,118],[405,450]]]

输出= [[[99,87],[100,118]],[[400,500] ,[405,450]],[[300,95],[297,107]]]





我是什么尝试过:



我试过这样的事情,也许计算一个子列表和另一个子列表的另一个子列表之间的x和y坐标之间的最小距离..

   i  范围( 1 ,len(listt)):
for sublist [i] 列表中的code-keyword>:
j 范围内( LEN(subli st [i]))
subsublist [j] 子列表[i]:

解决方案

你正在处理积分;所以你可以计算任意2点之间的距离,找到最接近的点。



c# - 计算2点之间的距离 - 堆栈溢出 [ ^ ]


引用:

如何找到另一个列表中最相似的子列表?



首先,您需要了解问题,并以明确的方式重新制定一个好的开始。

Quote:

每个子子列表看起来像[x,y]



每个子子列表是通常命名为的x和y坐标。

点的概念使得理解问题变得更容易。

Quote:

如何找到下一个子列表中最近的子子列表?



重新表示为:给定点,如何找到点列表中的最近点?

这是你问题的核心。

在你的问题中,列表只是重复同样的问题。 br />


除非你提供更多细节,否则蛮力可能是最好的方法。



获取你的帮助代码,显示它并解释你被卡住的地方。


I have a list of 60 sublists. Each sublist has 30 sub-sub lists. Each sub-sub-list looks like [x, y] For each sub-sub lists, how can I find the closest sub-sub list of the next sub-list?

For example, I am in sub-list[0], sub-sub-list[0]. Now I go to sub-list[1] and search for the sub-sub-list that has the closest x,y coordinates.

This is an example of what I am trying to accomplish:

input = [ [[99, 87], [400, 500], [300, 95]],
[[297, 107], [100, 118], [405, 450]] ]

output = [ [[99, 87],[100, 118]], [[400, 500], [405, 450]], [[300, 95], [297, 107]] ]



What I have tried:

I have tried something like this, maybe calculate the smallest distance between the x and y coordinates between a subsublist and another subsublist of another sublist..

for i in range(1,len(listt)):
    for sublist[i] in listt:
        for j in range(len(sublist[i]))
            for subsublist[j] in sublist[i]:

解决方案

You're dealing with "points"; so you can calculate the distance between any 2 points and find the one that is closest.

c# - Calculating the distance between 2 points - Stack Overflow[^]


Quote:

How to find the most similar sub list of another list?


First, you need to understand the problem, and reformulating in a clear way is a good start.

Quote:

Each sub-sub-list looks like [x, y]


Each sub-sub-list is x and y coordinates of what is commonly named a point.
The concept of point makes it easier to understand the problem.

Quote:

how can I find the closest sub-sub list of the next sub-list?


Is reformulated as: for a given point, how to find closest point in a list of points?
This is the heart of your problem.
In your problem, lists are just a repeat of same problem.

Unless you give more details, brute force is probably the best approach.

To get help on your code, show it and explain where you are stuck.


这篇关于如何找到另一个列表中最相似的子列表?蟒蛇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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