나는 컬렉션에서 GROUPBY 방법 선물을 사용하는 것이 좋습니다 것입니다 : 이것은 사용자가 지정한 판별에지도 벡터의 기반을 만들 것입니다
http://www.scala-lang.org/api/current/index.html#[email protected][K](f:A=>K):scala.collection.immutable.Map[K,Repr]
.
편집 : 일부 코드 예제 : 목록
// I created a different Array of Vector as I don't have Mahout dependencies
// But the output is similar
// A List of Vectors with 3 values inside
val num = 100
val data = (0 to num).toList.map(n => {
Vector(n % 30, n/100, n * 100)
})
// The groupBy will create a Map of Vectors where the Key is the result of the function
// And here, the function return the first value of the Vector
val group = data.groupBy(v => { v.apply(0) })
// Also a subset of the result:
// group:
// scala.collection.immutable.Map[Int,List[scala.collection.immutable.Vector[Int]]] = Map(0 -> List(Vector(0, 0, 0), Vector(0, 0, 3000), Vector(0, 0, 6000), Vector(0, 0, 9000)), 5 -> List(Vector(5, 0, 500), Vector(5, 0, 3500), Vector(5, 0, 6500), Vector(5, 0, 9500)))
그냥 내 대답을 편집했다. 그것이 도움이 되었으면 좋겠다 –
고마워,하지만 지금, 어떻게 합칠 것인가? –
지도의 각 값을 두 번째 및 세 번째 값을 합산 한 단일 벡터로 변환해야합니다. 목표는 [Double, Vector]의지도를 갖는 것입니다. 만약 당신이 신경 쓰지 않는다면, 당신이 스스로 시도해보고 성공하지 못한다면 그 예제를 제안 할 것입니다. –