数组归一化Normalize

归一化:0-1,结果*255
输入为二维数组,scala实现

/**
  * Created by zangtt on 17-6-23.
  */
class Normalize {
  //归一化 207400 * 3
  def fun(array: Array[Array[Double]]) = {
    val x = array(0).length     //3
    val y = array.length        //207400
    var max = -10000.0
    var min = 10000.0
    for (i <- 0 to (x - 1)) {
      for (j <- 0 to (y - 1)) {
        if (array(j)(i) > max) {
          max = array(j)(i)
        }
        if (array(j)(i) < min) {
          min = array(j)(i)
        }
      }
    }

    for (i <- 0 to (y - 1)) {
      array(i) = array(i).map(_ - min)
      array(i) = array(i).map(_ / max)
      array(i) = array(i).map(_ * 255.0)
    }
    array
  }
}

你可能感兴趣的:(常用函数,scala)