scala - how to add adjacent values in Array[Double] -


val values = array[double].sliding(2).map(x => x.reduce(_ + _) / 2) 

this works successfully. if array contains 10000 or more values, take times values. there faster method find adjacent values?

i think should faster:

val values = (for(i <- 0 until array.length - 1) yield ((array(i) + array(i + 1)) / 2)).toarray


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -