Skip to content

Instantly share code, notes, and snippets.

View jmborr's full-sized avatar
💭
👁️

Jose Borreguero jmborr

💭
👁️
View GitHub Profile
@jmborr
jmborr / clustering_timings
Created June 14, 2020 22:01
cluster 1000 3D points by euclidean distance
from scipy.cluster.hierarchy import fclusterdata
import numpy as np
import time
x = np.random.random((1000, 3))
start_time = time.time()
fclusterdata(x, 0.001, criterion='distance', metric='euclidean', method='complete')
print('elapsed time =', time.time() - start_time)
@jmborr
jmborr / gist:ebdf5b5893a7a40e08cce2d17175bfe2
Last active April 8, 2020 21:34
jsonschema validators using more than one instance
class ReductionParameters:
_validators = {'twoone': '_validate_two_using_one'}
def __init__(self, reduction_parameters, schema):
self._parameters = reduction_parameters
self._schema = schema
self._json_validator = None
self._initialize_json_validator()
def _validate_two_using_one(self, validator, value, instance, schema):
@jmborr
jmborr / namedtuplefy.py
Last active May 15, 2019 19:37
decorator to transform the return type of a function from dictionary to namedtuple
def namedtuplefy(func):
r"""
Decorator to transform the return dictionary of a function into
a namedtuple
Parameters
----------
func: Function
Function to be decorated
name: str