{"action":"created","issue":{"url":"https://api.github.com/repos/networkx/networkx/issues/2133","repository_url":"https://api.github.com/repos/networkx/networkx","labels_url":"https://api.github.com/repos/networkx/networkx/issues/2133/labels{/name}","comments_url":"https://api.github.com/repos/networkx/networkx/issues/2133/comments","events_url":"https://api.github.com/repos/networkx/networkx/issues/2133/events","html_url":"https://github.com/networkx/networkx/issues/2133","id":155181029,"number":2133,"title":"weighted directed Graph to undirected Graph","user":{"login":"Wuyanan520","id":16913304,"avatar_url":"https://avatars.githubusercontent.com/u/16913304?v=3","gravatar_id":"","url":"https://api.github.com/users/Wuyanan520","html_url":"https://github.com/Wuyanan520","followers_url":"https://api.github.com/users/Wuyanan520/followers","following_url":"https://api.github.com/users/Wuyanan520/following{/other_user}","gists_url":"https://api.github.com/users/Wuyanan520/gists{/gist_id}","starred_url":"https://api.github.com/users/Wuyanan520/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wuyanan520/subscriptions","organizations_url":"https://api.github.com/users/Wuyanan520/orgs","repos_url":"https://api.github.com/users/Wuyanan520/repos","events_url":"https://api.github.com/users/Wuyanan520/events{/privacy}","received_events_url":"https://api.github.com/users/Wuyanan520/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-17T05:40:35Z","updated_at":"2016-05-17T07:22:54Z","closed_at":null,"body":"I want to convert an weighted directed Graph to an weighted undirected Graph,looks like that\r\nmy weighted directed Graph is:\r\n1 2 2.0\r\n3 2 1.0\r\n2 3 2.0\r\n3 4 1.0\r\nI would get weighted undirected Graph:\r\n2 3 1.5\r\nwhich means \r\nedges in both directions (u,v) and (v,u) exist in the graph, weight for the new undirected edge will be mean of the two directed edges.\r\nhowever if either\r\n(u,v,data) or (v,u,data) is not in the digraph,the new undirected edge will not be existing"},"comment":{"url":"https://api.github.com/repos/networkx/networkx/issues/comments/219639129","html_url":"https://github.com/networkx/networkx/issues/2133#issuecomment-219639129","issue_url":"https://api.github.com/repos/networkx/networkx/issues/2133","id":219639129,"user":{"login":"Wuyanan520","id":16913304,"avatar_url":"https://avatars.githubusercontent.com/u/16913304?v=3","gravatar_id":"","url":"https://api.github.com/users/Wuyanan520","html_url":"https://github.com/Wuyanan520","followers_url":"https://api.github.com/users/Wuyanan520/followers","following_url":"https://api.github.com/users/Wuyanan520/following{/other_user}","gists_url":"https://api.github.com/users/Wuyanan520/gists{/gist_id}","starred_url":"https://api.github.com/users/Wuyanan520/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wuyanan520/subscriptions","organizations_url":"https://api.github.com/users/Wuyanan520/orgs","repos_url":"https://api.github.com/users/Wuyanan520/repos","events_url":"https://api.github.com/users/Wuyanan520/events{/privacy}","received_events_url":"https://api.github.com/users/Wuyanan520/received_events","type":"User","site_admin":false},"created_at":"2016-05-17T07:22:53Z","updated_at":"2016-05-17T07:22:53Z","body":"I finished it by \r\n1 2 2.0\r\n 3 2 1.0\r\n 2 3 2.0\r\n 3 4 1.0\r\nsaved as filename1\r\n\r\nwith open(filename1) as f:\r\n    G = nx.read_weighted_edgelist(f,create_using=nx.DiGraph())\r\n\r\nG1 = nx.Graph()\r\nfor u,v,data in G.edges_iter(data=True):\r\n    if G1.has_edge(u,v) or G1.has_edge(v,u):\r\n        continue\r\n    if G.has_edge(v,u):\r\n        w = np.mean([G[u][v]['weight'],G[v][u]['weight']])\r\n        G1.add_weighted_edges_from([(u,v,w)])\r\n\r\nwith open(filename2,'w') as f:    \r\n    nx.write_weighted_edgelist(G1,f)\r\n\r\nthen i get the file looks like\r\n2 3 1.5\r\nare there any different ways?"}}