import scala.util.Random
object LinearInterpolation {
def main(args: Array[String]) {
// Make random array
def randomArray(size:Int, max_val:Int)={
val rand = new Random
for (a <- 0 to size) yield rand.nextInt(max_val)
}
val data = randomArray(20, 100).toList
println("values:")
println(data)
// Find max and min value
val max_val = data.reduceLeft{ (a,b) => a max b }
val min_val = data.reduceLeft{ (a,b) => a min b }
println("max : " + max_val)
println("min : " + min_val)
// Do Linear Interpolation to change the range of values
val after = data.map(x => (x - min_val).toFloat / (max_val - min_val).toFloat)
println("after :")
println(after)
}
}