- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在spark中,我们可以很方便地使用map-reduce来统计单词出现的时间,并使用sort来获取top-k的频繁单词,
// Sort locally inside node, keep only top-k results,
// no network communication
val partialTopK = wordCount.mapPartitions(it => {
val a = it.toArray
a.sortBy(-_._2).take(10).iterator
}, true)
// Collect local top-k results, faster than the naive solution
val collectedTopK = partialTopK.collect
collectedTopK.size
// Compute global top-k at master,
// no communication, everything done on the master node
val topK = collectedTopK.sortBy(-_._2).take(10)
但我想知道是否有更好的解决方案完全避免排序?
最佳答案
我想你想要takeOrdered
Returns the first k (smallest) elements from this RDD as defined by the specified implicit Ordering[T] and maintains the ordering.
或top
Returns the top k (largest) elements from this RDD as defined by the specified implicit Ordering[T].
还有其他几个问题/答案似乎也至少部分重复
关于scala - 如何在不排序的情况下获取spark中的top-k频繁单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29310687/
我有一个包含值的字符串数组(duh...)。 有没有一种简单的方法可以获取出现次数最多的条目?有点像 values[37].getMostOften(); 干杯:) 最佳答案 您可以使用GroupBy
我目前正在将一款用 C#(适用于 Windows Phone)开发的游戏移植到 Java (Android)。 我们在 Java 版本中遇到了内存问题,在分析之后,似乎是由于内存中的大量 String
对于播放音频文件的 iPhone 应用程序,我正在开发一个系统来跟踪用户在他们听过的任何一集中的进度(例如,他们听 file1 的前 4:35,然后开始另一个文件,然后返回到文件 1,它从 4:35
如果您按下 UIbutton 显示 UITextView,将请求代码 Ì 再次按下 UIbutton 再次显示 UITextView :/ 最佳答案 .h 文件中只有一个 int 变量,如下所示..
我在 Application_End 上处理的项目中使用临时数据库: protected void Application_End() { if (_db != null) _db.Dispo
我是一名优秀的程序员,十分优秀!