Last active
July 16, 2019 08:04
-
-
Save kristoff-it/4470e247a4867fd5c3ad7baf7547d197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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