use strict;
use warnings;
my @not_normalized = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
my @normalized = normalizer(@not_normalized);
print "@normalized";
sub normalizer {
# to normalize an input array bw 0 and 1
my @array = @_;
use List::Util qw( min max ); # import min and max module
my $min_numarray = min @array; # get min of args
my $max_numarray = max @array; # get max of args
my $numden = $max_numarray - $min_numarray; # denominator: max tot
+al - min total
foreach my $index (0..$#array) { # loop over args
my $numdiv = $array[$index] - $min_numarray; # numerator: n
+ - min total
$array[$index] = $numdiv / $numden; # normalize
}
return @array;
}
I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious
|