Skip to content

Instantly share code, notes, and snippets.

View maxhully's full-sized avatar

Max Hully maxhully

View GitHub Profile
@maxhully
maxhully / partition_idea.py
Created October 12, 2018 16:27
Partition Idea
from collections import defaultdict
import random
import networkx
import pandas
def propose_any_node_flip(partition):
node = random.choice(tuple(partition.assignment.keys()))
part = random.choice(tuple(partition.parts.keys()))
return partition.flip({ node: part })
@maxhully
maxhully / coord_distance.py
Last active September 10, 2018 15:24
Computes the matrix of distances between centroids of polygons
import numpy as np
import geopandas
def quadratic_distance(x, y):
return np.sum(np.square(np.array(x) - np.array(y)))
def distance_matrix(points):
N = len(points)