【发布时间】:2017-01-03 13:36:29
【问题描述】:
我正在尝试将 spark 数据帧 traindf 转换为 4-d numpy 数组。我试过这个:
traindf = sqlContext.createDataFrame([
(1, 1, 2, 3),
(1, 2, 2, 3),
(1, 3, 2, 3),
(1, 4, 2, 3),
(2, 4, 5, 6),
(2, 4, 5, 6),
(3, 7, 8, 9),
(2, 4, 5, 6),
(3, 7, 8, 9),
(3, 7, 8, 9)
], ("id", "image", "s", "t"))
values = (traindf.rdd.map(lambda l: [map(lambda r: float(r), l)]).collect())
x = np.array(values)
x = np.array_split(x, x.shape[0]/2)
x = np.asarray(x)
x.shape
这会产生 (5, 2, 1, 4),但似乎 keras 需要 (5, 1, 2, 4)。我尝试了几种方法,但没有找到获得正确格式的好方法。
有什么建议吗?
【问题讨论】:
标签: python numpy apache-spark pyspark keras