Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Last active July 16, 2019 08:04
Show Gist options
  • Save kristoff-it/4470e247a4867fd5c3ad7baf7547d197 to your computer and use it in GitHub Desktop.
Save kristoff-it/4470e247a4867fd5c3ad7baf7547d197 to your computer and use it in GitHub Desktop.
# script.py
import numpy as np
def hash2list(redis_key):
h = redis_key['value'] # redis_key contains 'key' and 'value'
return [float(h['x']), float(h['y']), float(h['z'])]
def do_mean(acc, x):
if acc is None:
return x
return np.mean([acc, x], axis=0)
GearsBuilder()\
.map(hash2list)\
.accumulate(do_mean)\
.flatmap(lambda x: x.tolist())\
.run("vec:*")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment