如何合并元素明智的2 RDDS [英] How to merge element-wise two RDDs
本文介绍了如何合并元素明智的2 RDDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有两个RDDS像
Suppose I have two RDDs like
第一个
1
2
3
4
5
第二
6
7
8
9
10
新RDD是
1 6
2 7
3 8
4 9
5 10
所以,这是基本元素明智合并......我们假定两个RDDS是大小相同的。
So, this is basically element wise merge...We assume that the two RDDs are of same size.
推荐答案
您可以使用星火公司的拉链功能。按照Doc:
You can use Spark's zip function. As per doc:
>>> x = sc.parallelize(range(0,5))
>>> y = sc.parallelize(range(1000, 1005))
>>> x.zip(y).collect()
[(0, 1000), (1, 1001), (2, 1002), (3, 1003), (4, 1004)]
请注意,此函数假定相同的分区数和相同数量的两种RDDS元素
Be aware that this function assumes the same number of partitions and the same number of elements in both RDDs.
这篇关于如何合并元素明智的2 RDDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文