如何在python中从igraph导出?



我写了这段代码来转换。gml格式的数据,但我得到了这个错误。我该怎么办?

TypeError: descriptor 'write_gml' for 'igraph._igraph.GraphBase' objects doesn't apply to a 'str' object

代码:

import igraph as ig
import pandas as pd

a = pd.DataFrame(Matrix, index=tags, columns=tags)

# # Get the values as np.array, it's more convenenient.
A = a.values
# print(A)
# # Create graph, A.astype(bool).tolist() or (A / A).tolist() can also be used.
g = igraph.Graph.Adjacency((A > 0).tolist())
# # Add edge weights and node labels.
g.es['weight'] = A[A.nonzero()]
g.vs['label'] = tags  # or a.index/a.columns
ig.Graph.write_gml('test.gml')

如果要将图形g写入filename,则需要调用g.write_gml(filename)

相关内容

  • 没有找到相关文章

最新更新