Skip to content

Instantly share code, notes, and snippets.

@jwintersinger
Last active August 27, 2015 23:21
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 jwintersinger/1a881308397bd219b805 to your computer and use it in GitHub Desktop.
Save jwintersinger/1a881308397bd219b805 to your computer and use it in GitHub Desktop.
Initial:
[[0 1 1 0 1]
[0 0 1 0 1]
[0 0 0 0 0]
[0 1 1 0 1]
[0 0 0 0 0]]
Top:
[[0 1 1 0 1]
[0 0 1 0 1]
[0 0 0 0 0]
[0 0 0 0 1]
[0 0 0 0 0]]
Bottom:
[[0 0 0 0 0]
[1 0 0 0 0]
[1 1 0 0 0]
[0 0 0 0 0]
[1 1 1 1 0]]
Combined:
[[0 1 1 0 1]
[1 0 1 0 1]
[1 1 0 0 0]
[0 0 0 0 1]
[1 1 1 1 0]]
import numpy as np
assignment = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0], [0, 0, 0, 1]])
node_ancestry = np.array([[0, 1, 1, 1], [0, 0, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]])
print('Initial:')
adm_top = np.dot(np.dot(assignment, node_ancestry), assignment.T)
print(adm_top)
print
adm_top = np.triu(adm_top)
node_ancestry = np.logical_not(node_ancestry)
np.fill_diagonal(node_ancestry, 0)
adm_bottom = np.dot(np.dot(assignment, node_ancestry), assignment.T)
adm_bottom = np.tril(adm_bottom)
adm = adm_top + adm_bottom
print('Top:')
print(adm_top)
print
print('Bottom:')
print(adm_bottom)
print
print('Combined:')
print(adm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment