小编New*_*his的帖子

最近邻算法

好吧,我对编程还很陌生。我正在使用 Python 2.7,我的下一个目标是实现一些轻型版本的最近邻算法(请注意,我不是在谈论 k 最近邻)。我尝试了很多方法,其中一些很接近,但我似乎仍然无法确定。

首先, - 我使用一个数组来表示我的事件矩阵,这是一个好主意吗?我在这里想到 numpys 数组和矩阵。

其次,-我知道算法(伪代码),它非常简单。但我绝对可以使用某种启动方式。我对完整的实施不感兴趣,但我现在有库存,我正在寻求一些帮助。

也许以上还不足以澄清我的问题,但请随时提问。

先感谢您。

好吧,现在我又试了一次。我想我似乎已经明白了——无论如何,这就是我所做的。我对结果非常满意,因为我对此还很陌生。但我确信您有一些提示或改进。

import numpy as np
import copy

'''
                        NEAREST NEIGHBOUR ALGORITHM
                        ---------------------------


The algorithm takes two arguments. The first one is an array, with elements
being lists/column-vectors from the given complete incidensmatrix. The second 
argument is an integer which represents the startingnode where 1 is the 
smallest. The program will only make sense, if the triangle inequality is satisfied.
Furthermore, diagonal elements needs to be …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-2.7 ×1