2016-12-15 64 views
-3

组合这可以先验算法斯卡拉星火阵列无需重复

是有用的我有2列:

scala> a.take(3) 
res1: Array[String] = Array(cat, dog, bird) 
scala> b.take(3) 
res2: Array[String] = Array(cat, dog, bird) 

我如何能做到对组合,而无需重复配对? 因此,例如:

与>(cat,dog) 但与重复>(dog, cat)

scala> for (a_ <- a; b_ <-b) yield (a_, b_)  
<console>:35: error: type mismatch; 
found : org.apache.spark.rdd.RDD[(String, String)] 
required: TraversableOnce[?] 

最后,我只想有:

(cat, dog) 
    (cat, bird) 
    (dog, bird) 
+3

请包括代码为文字而不是图像 –

+0

请发表你自己写的一个解决方案,试图 – radumanolescu

+1

你可以找到解决方案[这里](HTTPS一些代码://i.imgur.com/dsBsmbR.png) – Odomontois

回答

-1

我们使用的过滤器X <ÿ ,那么我们不需要订购,因为这将排除所有不正确的配对。

最后的答案是:

val combinations = a.cartesian(b).filter{case(x,y) => x < y} 
+0

非常确定,数组没有在标准隐式丰富中定义的'笛卡尔'操作 – Odomontois

+0

@Odomontois,它是一个RDD,尽管来自OP的示例代码。查看错误消息。 –