Created
September 4, 2020 08:23
-
-
Save mikk-c/5df626c564157fb5242701591ca4f38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import networkx as nx" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"G1 = nx.read_edgelist(\"1/data1.txt\", delimiter = \"\\t\", nodetype = int)\n", | |
"G2 = nx.read_edgelist(\"1/data2.txt\", delimiter = \"\\t\", nodetype = int)\n", | |
"G3 = nx.read_edgelist(\"1/data3.txt\", delimiter = \"\\t\", nodetype = int)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"edges = []\n", | |
"for n1 in range(len(G1.nodes) - 1):\n", | |
" for n2 in range(n1 + 1, len(G2.nodes)):\n", | |
" count = 0\n", | |
" if (n1, n2) in G1.edges or (n2, n1) in G1.edges:\n", | |
" count += 1\n", | |
" if (n1, n2) in G2.edges or (n2, n1) in G2.edges:\n", | |
" count += 1\n", | |
" if (n1, n2) in G3.edges or (n2, n1) in G3.edges:\n", | |
" count += 1\n", | |
" if count >= 2:\n", | |
" edges.append((n1, n2))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"Gc = nx.Graph(edges)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment