根据邻接矩阵绘制无向图

from igraph import *
import numpy as np
import matplotlib.pyplot as plt
def matrixgraph(matrix):
    G = Graph()#无向图
    n = len(matrix)
    print(n)
    lielist=np.sum(matrix, axis=0)  # 每一列的和
    for i in range(n):
        if lielist[i]>0:
            G.add_vertices(i)
    for i in range(n):
        for j in range(n):
            if matrix[i][j] > 0:
                G.add_edges([(i,j)])
    return G

上一篇:AI 学习 | 足球赛果预测


下一篇:numpy总结