问题描述
我想使用共现矩阵作为输入在 Python 中绘制一个网络,以便连接具有非零共现计数的节点,并且边的权重与 co 的数量成正比- 每个节点之间的出现次数.
I want to plot a network in Python using a co-occurence matrix as an input, such that nodes that have a non-zero co-occurence count are connected, and the weight of the edges is proportional to the number of co-occurrences between each node.
是否有一个 Python 库可以使用共现矩阵作为输入来促进这项任务?
Is there a python library in existence that will facilitate this task using a co-occurence matrix as an input?
推荐答案
您可能会发现 NetworkX一个有用的工具.您可以通过多种方式轻松地为它提供输入节点和边.
You might find NetworkX to be a useful tool for that. You can easily feed it the input nodes and edges in several ways.
如果你想使用共现矩阵生成你的网络,你可以使用NetworkX的方法from_numpy_matrix,它允许您从 numpy 矩阵矩阵创建一个图形,该矩阵将被解释为邻接矩阵.
In the case that you want to generate your network using a co-occurrence matrix, you can use NetworkX's method from_numpy_matrix, which allows you to create a graph from a numpy matrix matrix which will be interpreted as an adjacency matrix.
这是文档中的一个简单的玩具示例:
Here's a simply toy example from the documentation:
import numpy as np
import networkx as nx
A=np.matrix([[1,1],[2,1]])
G=nx.from_numpy_matrix(A)
这篇关于使用共现矩阵绘制网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!