【发布时间】:2018-05-06 14:30:22
【问题描述】:
在 Pyspark 上,我将 UDF 定义如下:
from pyspark.sql.functions import udf
from scipy.spatial.distance import cdist
def closest_point(point, points):
""" Find closest point from a list of points. """
return points[cdist([point], points).argmin()]
udf_closest_point = udf(closest_point)
dfC1 = dfC1.withColumn("closest", udf_closest_point(dfC1.point, dfC1.points))
我的数据如下所示:
- point = [0.2,0.5] 或 [0.1,0.6] - 浮点数组
- points = [[0,1],[1,0],[1,1],[0,0]] - 浮点数组数组
- closest = 例如,'[0, 1]' - 一个字符串(它是值之一 从点转换为字符串)
我应该对我的 UDF 进行哪些更改以返回浮点数组而不是字符串?
【问题讨论】: