Skip to content

Instantly share code, notes, and snippets.

@mikk-c
Created October 3, 2018 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikk-c/95d53ae0853cb50a624481cebafa8f5e to your computer and use it in GitHub Desktop.
Save mikk-c/95d53ae0853cb50a624481cebafa8f5e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#The goal of the exercise is to show that (Laplacian = Degree matrix - Adjacency matrix)\n",
"import networkx as nx \n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Read the input data\n",
"g = nx.read_edgelist(\"data/protein.txt\", delimiter='\\t')"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"#Get the adjacency matrix\n",
"\n",
"A = nx.to_numpy_matrix(g)\n",
"\n",
"D = np.diagflat(A.sum(axis=1))\n",
"\n",
"L = nx.laplacian_matrix(g).todense()\n",
"\n",
"print(np.all(L==(D-A)))"
]
}
],
"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.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment