写一个函数boundary_dense,它取一个密集的数组A,表示一个图形作为adjecency矩阵,和一个向量U,用它们在A中的索引表示图形的顶点 .

该函数应返回边缘deltaU数组,这是U的边界 . 您的代码不能显式调用Networkx模块中的任何函数 . 特别是,您不能调用networkx.algorithms.boundary.edge_boundary

def boundary_dense(A,U):
  arr = np.asarray(A)
  B = (np.argwhere(arr > 0))
  for i in U:
    C=(B[B[:,0] == i])  
    print(C)

我们得到这样的矩阵:[0,6,2,4,0 6,0,0,1,4 2,0,0,1,5 4,1,1,0,2 0,2,5 ,2,0]

然后我们的函数是boundary_Dense(A,U)其中A是矩阵,U是多达三个输入的一些选择,范围表示矩阵的行,例如: [1,2]或[1]或[0,2,3]等

我们需要函数来提供与U相关的行中所有非零条目的索引,从而排除列U. entries of U can not be larger than 3