Created
December 28, 2014 20:31
-
-
Save iszlai/494128e7967ac0d475f9 to your computer and use it in GitHub Desktop.
Dot product calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dot(first: Array[Array[Double]], second: Array[Int]): Array[Double] = { | |
val result = new Array[Double](first.size) | |
for (i <- 0 to (first.size - 1)) { | |
result(i) = dotProduct(first(i), second) | |
} | |
return result | |
} | |
def dotProduct(first: Array[Double], second: Array[Int]): Double = { | |
require(first.size == second.size) | |
(for ((a, b) <- first zip second) yield a * b) sum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment