I have two arrays:
val diceProbDist = new Array[Double](2 * DICE + 1)
and
val diceExpDist = new Array[Double](2 * DICE + 1)
and I want to merge in one single structure (some sort of tuple, maybe):
(0, 0.0, 0,0)(1, 0.0, 0.0)(2, 0.02778, 0.02878)...
where the first entry is the array index, the second entry is the first array value and the third entry is the second array value.
Is there some scala function to accomplish that (zip with map or something like that)?
thanks, ML
val diceProbDist = Array(0.1, 0.2, 0.3)
val diceExpDist = Array(0.11, 0.22, 0.33)
diceProbDist
.zip(diceExpDist)
.zipWithIndex
.map { case ((v1, v2), i) => (i, v1, v2) }
// result: Array((0,0.1,0.11), (1,0.2,0.22), (2,0.3,0.33))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With