如何计算数组的逐元素总和?
val a = new Array[Int](5)
val b = new Array[Int](5)
// assign values
// desired output: Array -> [a(0)+b(0), a(1)+b(1), a(2)+b(2), a(3)+b(3), a(4)+b(4)]
a.zip(b).flatMap(_._1+_._2)
missing parameter type for expanded function
最佳答案
尝试:
a.zip(b).map { case (x, y) => x + y }
关于arrays - Scala 中数组的按元素求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35064883/