给定图G,我们得到G -
中一对节点(p,q)的得分我想计算这个函数的值,其中L(p)表示节点p的无向链路邻居集合(C是常数)
我知道如何分别从邻接矩阵中计算out和in link邻居,这是 -
$excelname = 'Testing';
$objPHPExcel = new \PHPExcel();
header('Content-Type: application/vnd.ms-excel');
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header('Content-Disposition: attachment;filename="' . $excelname . ' Template.xlsx"');
$objWriter2 = new \PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter2->save('php://output');
但是我想直接计算一组无向链接邻居。给我们的输入是一个邻接矩阵,图形类型是定向的。
答案 0 :(得分:0)
感谢@Paul这是我得到的答案 -
a = np.array([ [0, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
[1, 0, 0, 0, 0],
[0, 0, 0, 0, 1],
[0, 0, 0, 1, 0] ])
a_transpose=np.transpose(a)
a_undirected=np.add(a,a_transpose)
self.num_nodes = np.shape(a)[0]
current_sim = np.eye(self.num_nodes)
prev_sim = np.zeros(shape=(self.num_nodes, self.num_nodes))
# Determine the set of In-Neighbors for each node
nbs = []
for i in range(self.num_nodes):
nbs.append(np.nonzero(a_undirected[:, i])[0])
输出 - [
array([1, 2, 3], dtype=int64), array([0, 2], dtype=int64), array([0, 1], dtype=int64), array([0, 4], dtype=int64), array([3], dtype=int64)]