Convert Array[Array[Double]] to Array[Double]

638 views Asked by At

How can I convert an array of arrays of doubles to just an array of doubles using Scala 2.10.4?

Convert: Array[Array[Double]] => Array[Double]

2

There are 2 answers

0
Jean Logeart On BEST ANSWER

Use flatten:

val r: Array[Double] = doubleDouble.flatten
0
Denis On

You can write something like this:

val src = Array(Array(1.2,3.4), Array(5.6, 7.8))

val result = for {
a <- src
b <- a
} yield b