Skip to content

Instantly share code, notes, and snippets.

@afranzi
Last active June 20, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afranzi/c08eec19bda799f67976402c20aafe3d to your computer and use it in GitHub Desktop.
Save afranzi/c08eec19bda799f67976402c20aafe3d to your computer and use it in GitHub Desktop.
def personality_udf(personality_mapping: dict):
@udf(returnType=IntegerType())
def inner(cat):
return personality_mapping.get(cat, -1)
return inner
def compute_gvector_udf(personality_mapping: dict):
@udf(returnType=ArrayType(DoubleType()))
def inner(ngvector, cgvector, suma):
result = [0.] * len(personality_mapping)
for i in range(len(ngvector)):
result[ngvector[i]] = cgvector[i] / suma
return result
return inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment