Mathematica : duplicate edges
I am trying to generate a graph from an adjacency list, but Mathematica doesn't want to plot my graph because of multiple edges i think. This is my script :
Needs["GraphUtilities`"]
data = Import["adj_matrix.txt", "Table"];
data2 = Flatten[Table[{data[[i, 1]] [UndirectedEdge] data[[i, 2]]}, {i, 1,
Length[data]}]];
graph1 = Graph[data2]
The error i get is : Graph::supp: Mixed graphs and multigraphs are not supported.
I do not have any "proper" duplicates in my list, the only type of duplicates that appear are 1->2 and 2->1. I would like to know how to delete these "duplicates" from my list.
You can directly convert an adjacency matrix to a Graph
using AdjacencyGraph[]
. This is probably the simplest solution:
AdjacencyGraph[data]
If your matrix contains other elements than 0 and 1, use
AdjacencyGraph@Clip[data]
To filter out duplicates from the edge list of an undirected graph, use
Union[Sort /@ edgeList]
链接地址: http://www.djcxy.com/p/20254.html
上一篇: Mathematica combinatorica包:避免图形渲染
下一篇: Mathematica:重复的边缘