{"action":"created","issue":{"url":"https://api.github.com/repos/networkx/networkx/issues/1307","labels_url":"https://api.github.com/repos/networkx/networkx/issues/1307/labels{/name}","comments_url":"https://api.github.com/repos/networkx/networkx/issues/1307/comments","events_url":"https://api.github.com/repos/networkx/networkx/issues/1307/events","html_url":"https://github.com/networkx/networkx/pull/1307","id":52060167,"number":1307,"title":"Adds a graph power operation.","user":{"login":"jfinkels","id":121755,"avatar_url":"https://avatars.githubusercontent.com/u/121755?v=3","gravatar_id":"","url":"https://api.github.com/users/jfinkels","html_url":"https://github.com/jfinkels","followers_url":"https://api.github.com/users/jfinkels/followers","following_url":"https://api.github.com/users/jfinkels/following{/other_user}","gists_url":"https://api.github.com/users/jfinkels/gists{/gist_id}","starred_url":"https://api.github.com/users/jfinkels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfinkels/subscriptions","organizations_url":"https://api.github.com/users/jfinkels/orgs","repos_url":"https://api.github.com/users/jfinkels/repos","events_url":"https://api.github.com/users/jfinkels/events{/privacy}","received_events_url":"https://api.github.com/users/jfinkels/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/networkx/networkx/labels/Enhancement","name":"Enhancement","color":"009800"},{"url":"https://api.github.com/repos/networkx/networkx/labels/Needs%20review","name":"Needs review","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/networkx/networkx/milestones/3","html_url":"https://github.com/networkx/networkx/milestones/networkx-2.0","labels_url":"https://api.github.com/repos/networkx/networkx/milestones/3/labels","id":236124,"number":3,"title":"networkx-2.0","description":"","creator":{"login":"hagberg","id":187875,"avatar_url":"https://avatars.githubusercontent.com/u/187875?v=3","gravatar_id":"","url":"https://api.github.com/users/hagberg","html_url":"https://github.com/hagberg","followers_url":"https://api.github.com/users/hagberg/followers","following_url":"https://api.github.com/users/hagberg/following{/other_user}","gists_url":"https://api.github.com/users/hagberg/gists{/gist_id}","starred_url":"https://api.github.com/users/hagberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hagberg/subscriptions","organizations_url":"https://api.github.com/users/hagberg/orgs","repos_url":"https://api.github.com/users/hagberg/repos","events_url":"https://api.github.com/users/hagberg/events{/privacy}","received_events_url":"https://api.github.com/users/hagberg/received_events","type":"User","site_admin":false},"open_issues":32,"closed_issues":88,"state":"open","created_at":"2012-12-29T15:43:08Z","updated_at":"2015-03-06T22:09:34Z","due_on":"2015-09-15T04:00:00Z","closed_at":null},"comments":37,"created_at":"2014-12-16T00:55:10Z","updated_at":"2015-03-07T19:13:41Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/networkx/networkx/pulls/1307","html_url":"https://github.com/networkx/networkx/pull/1307","diff_url":"https://github.com/networkx/networkx/pull/1307.diff","patch_url":"https://github.com/networkx/networkx/pull/1307.patch"},"body":"This adds the `networkx.algorithms.operators.product.pow` function, which\r\ncomputes a power of a given a graph. If SciPy is available, this\r\nfunction computes the power of the adjacency matrix of the graph. If\r\nSciPy is not available, it falls back to a naive (and slow)\r\nexponentiation-by-squaring implementation using only the graph\r\nprimitives provided by NetworkX."},"comment":{"url":"https://api.github.com/repos/networkx/networkx/issues/comments/77704761","html_url":"https://github.com/networkx/networkx/pull/1307#issuecomment-77704761","issue_url":"https://api.github.com/repos/networkx/networkx/issues/1307","id":77704761,"user":{"login":"MridulS","id":5363860,"avatar_url":"https://avatars.githubusercontent.com/u/5363860?v=3","gravatar_id":"","url":"https://api.github.com/users/MridulS","html_url":"https://github.com/MridulS","followers_url":"https://api.github.com/users/MridulS/followers","following_url":"https://api.github.com/users/MridulS/following{/other_user}","gists_url":"https://api.github.com/users/MridulS/gists{/gist_id}","starred_url":"https://api.github.com/users/MridulS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MridulS/subscriptions","organizations_url":"https://api.github.com/users/MridulS/orgs","repos_url":"https://api.github.com/users/MridulS/repos","events_url":"https://api.github.com/users/MridulS/events{/privacy}","received_events_url":"https://api.github.com/users/MridulS/received_events","type":"User","site_admin":false},"created_at":"2015-03-07T19:13:41Z","updated_at":"2015-03-07T19:13:41Z","body":"Should we include a power function for MultiGraphs, I couldn't find any literature on power of MultiGraphs. \r\n@dschult For excluding self loops we can modify @hagberg code to:\r\n``` python\r\nimport networkx as nx\r\nfrom itertools import izip_longest\r\ndef pow(G,k):\r\n    H = nx.Graph()\r\n    for n in G:\r\n        p = nx.single_source_shortest_path_length(G,n,cutoff=k)\r\n        for key,value in p:       #remove self loops\r\n             if value == 0:\r\n                 del p[key]\r\n        H.add_edges_from(izip_longest([n],p,fillvalue=n))\r\n    return H\r\n\r\nif __name__=='__main__':\r\n#    G = nx.cycle_graph(5)\r\n    G = nx.grid_2d_graph(5,3)\r\n    H = pow(G,2)\r\n    print H.edges()\r\n```\r\n\r\nShould I send in a patch with tests and documentation?"}}