Normalise a list of numbers to the range 0 - 1
Update to fix $min == $max buguse strict; use warnings; use List::MoreUtils qw(minmax); my @numbers = (23, 4, -6.5, 10.7, 123, 99.5); my ($min, $max) = minmax (@numbers); my $scale = 1.0 / ($max == $min ? $max : $max - $min); @numbers = map {($_ - $min) * $scale} @numbers; print join ", ", @numbers;
In reply to Normalise numbers by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |