Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
2D Gaussian function in Scala
import scala.math._
def gauss(dim: Int, sigma: Float): Array[Array[Float]] = {
throw new Exception("dim must be odd.")
val arr = Array.fromFunction(i=>{
val x = (i - (dim-1)/2).toFloat
val y = (j - (dim-1)/2).toFloat
(exp(-1 * pow(x/sigma,2)) * exp(-1 * pow(y/sigma,2))).toFloat
val ret =>>b/sum(arr)))
def sum(arr: Array[Array[Float]]): Float = {>row.sum).sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.