Skip to content

Instantly share code, notes, and snippets.

View vtraag's full-sized avatar
🏡
I may be slow to respond.

Vincent Traag vtraag

🏡
I may be slow to respond.
View GitHub Profile
Verifying that +vtraag is my blockchain ID. https://onename.com/vtraag
# Create horizontal line from axis border to axis border.
\draw[thick,color=black]
({axis cs:0,1}-|{rel axis cs:0,0}) --
({axis cs:0,1}-|{rel axis cs:1,0});
@vtraag
vtraag / permute_sparse_matrix.py
Last active December 18, 2024 22:33
Permute sparse matrix in Python using scipy COO format
def permute_sparse_matrix(M, order):
permuted_row = order[M.row];
permuted_col = order[M.col];
new_M = sparse.coo_matrix((M.data, (permuted_row, permuted_col)), shape=M.shape);
return new_M;
@vtraag
vtraag / get_sparse_adjacency_matrix.py
Last active January 29, 2017 15:07
Create sparse matrix from igraph in python
def get_sparse_adjacency_matrix(G, attr=None):
if attr:
source, target, data = zip(*[(e.source, e.target, e[attr])
for e in G.es if not np.isnan(e[attr])]);
else:
source, target = zip(*[(e.source, e.target)
for e in G.es]);
data = np.ones(len(source)).astype('int').tolist();
if not G.is_directed():
# If not directed, also create the other edge