2
 def clu(allcenter:Array[Int], data:Array[Array[Double]], cnum : Int) = {
     val alldata = (data, allcenter).zipped.map { case (a, b) => b.toDouble +: a}

after this I want to filter alldata's first element and get the remain element

like this:

alldata.fliter(_._1 == 10).map(case(a,b,c) => (b,c)) //it's way in tuple

how can I rewrite above statement in array way? thank you!

4

1 回答 1

4

You can write it like this:

alldata
  .filter(_(0) == 10)
  .map {
    case Array(a, b, c) => (b, c) // from array to tuple
  }

However, you can also do both at the same time:

alldata collect {
  case Array(10, b, c) => (b, c)
}
于 2013-11-06T04:29:54.163 回答