Skip to content

Instantly share code, notes, and snippets.

@TaylorOshan
Created July 8, 2016 21:49
Show Gist options
  • Select an option

  • Save TaylorOshan/51e320a9c5db0a8b564458c07af8f4cb to your computer and use it in GitHub Desktop.

Select an option

Save TaylorOshan/51e320a9c5db0a8b564458c07af8f4cb to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"os.chdir('/Users/toshan/dev/pysal/pysal/weights')\n",
"from spintW import netW, mat2L"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"link_list = [('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'a'), ('b', 'c'), ('b', 'd'), ('c', 'a'), ('c', 'b'), ('c', 'd'), ('d', 'a'), ('d', 'b'), ('d', 'c')]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 0.],\n",
" [ 1., 0., 1., 1., 1., 0., 1., 1., 1., 1., 0., 1.],\n",
" [ 1., 1., 0., 1., 0., 1., 1., 0., 1., 1., 1., 1.],\n",
" [ 1., 1., 1., 0., 1., 1., 1., 1., 0., 1., 1., 0.],\n",
" [ 1., 1., 0., 1., 0., 1., 1., 1., 1., 0., 1., 1.],\n",
" [ 1., 0., 1., 1., 1., 0., 0., 1., 1., 1., 1., 1.],\n",
" [ 1., 1., 1., 1., 1., 0., 0., 1., 1., 1., 0., 1.],\n",
" [ 1., 1., 0., 1., 1., 1., 1., 0., 1., 0., 1., 1.],\n",
" [ 0., 1., 1., 0., 1., 1., 1., 1., 0., 1., 1., 1.],\n",
" [ 1., 1., 1., 1., 0., 1., 1., 0., 1., 0., 1., 1.],\n",
" [ 1., 0., 1., 1., 1., 1., 0., 1., 1., 1., 0., 1.],\n",
" [ 0., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 0.]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = netW(link_list)\n",
"w.full()[0]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 1.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0.]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = netW(link_list, share='O')\n",
"w.full()[0]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0.],\n",
" [ 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1.],\n",
" [ 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0.],\n",
" [ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.],\n",
" [ 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., 0.],\n",
" [ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],\n",
" [ 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0.],\n",
" [ 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],\n",
" [ 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = netW(link_list, share='D')\n",
"w.full()[0]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 1., 1., 0., 0., 0., 0., 1., 0., 0., 1., 0.],\n",
" [ 1., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0., 1.],\n",
" [ 1., 1., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 1., 1., 1., 0., 0., 1., 0., 0.],\n",
" [ 0., 1., 0., 1., 0., 1., 0., 0., 0., 0., 0., 1.],\n",
" [ 0., 0., 1., 1., 1., 0., 0., 0., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 0., 0., 0., 1., 1., 1., 0., 0.],\n",
" [ 1., 0., 0., 0., 0., 0., 1., 0., 1., 0., 1., 0.],\n",
" [ 0., 0., 1., 0., 0., 1., 1., 1., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 1., 1.],\n",
" [ 1., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 1.],\n",
" [ 0., 1., 0., 0., 1., 0., 0., 0., 0., 1., 1., 0.]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = netW(link_list, share='OD')\n",
"w.full()[0]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 0., 0., 1., 1., 1., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 1., 1., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 1.],\n",
" [ 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 1., 1., 1., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 1.],\n",
" [ 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 1., 1., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 1.],\n",
" [ 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 1., 1., 1., 0., 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0., 0., 1., 1., 1., 0., 0., 0.]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = netW(link_list, share='C')\n",
"w.full()[0]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[0, 1, 1],\n",
" [1, 0, 1],\n",
" [1, 1, 0]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat = np.array([[0,1,1],[1,0,1],[1,1,0]])\n",
"mat"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"adjL = mat2L(mat)\n",
"adjL"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 0., 1., 1., 0., 0.],\n",
" [ 0., 0., 0., 0., 1., 1.],\n",
" [ 1., 1., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 1., 1.],\n",
" [ 1., 1., 0., 0., 0., 0.],\n",
" [ 0., 0., 1., 1., 0., 0.]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = netW(adjL, share='C')\n",
"w.full()[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment