我有4个索引为0,1,2和3的点,它们彼此之间都有关系,可以通过网络或下面的二维数组来捕获.我想根据一个阈值将这些数字分组在一起,这样,如果边缘超过阈值,则将这些点分组在一起.
import numpy as np
np.array([[1.0, 0.2, 0.3, 0.4],
[0.2, 1.0, 0.7, 0.5],
[0.3, 0.7, 1.0, 0.2],
[0.4, 0.5, 0.2, 1.0]])
以上示例在不同的阈值下,我的结果将是:
threshold = 0.6
result = [[0], [1,2], [3]]
#node 0 and 3 connections are all less than the threshold but
#nodes 1 and 2 have an edge of 0.7 which is greater than the threshold.
threshold = 0.8
result = [[0],[1],[2],[3]]
threshold = 0.1
result = [[0,1,2,3]]
我想构建一个函数,它可以用任意N×N矩阵对任意阈值执行此操作.所有边都在0
到1.0
之间.对角线将始终为1.0
,并且矩阵将始终是对称的,如本例所示.