Skip to content

Instantly share code, notes, and snippets.

View blogle's full-sized avatar

Brandon Ogle blogle

  • Standard Cognition
  • Bellingham, WA
View GitHub Profile
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@blogle
blogle / query_subset_testing.py
Last active August 29, 2015 14:11
scipy/kdtree.query_subset
import numpy as np
from scipy.spatial import KDTree
def minkowski_distance_p(x, y, p=2):
"""
Compute the p-th power of the L**p distance between two arrays.
For efficiency, this function computes the L**p distance but does
not extract the pth root. If `p` is 1 or infinity, this is equal to
the actual L**p distance.
import numpy as np
import networkx as nx
import heapq
from collections import defaultdict
def distance(u, v):
return np.sum((u - v)**2)
class KDTree(object):
@blogle
blogle / Choose Function
Created April 24, 2014 20:51
efficient calculation of nCr using sets
def choose(n,k):
"efficient calculation of nCr using sets"
if n < k:
raise ValueError('n < k')
n_set, k_set = set(range(1,n+1)), set(range(1,k+1))
n_min_k_set = set(range(1,(n-k)+1))
if len(n_min_k_set) < len(k_set):