perl Statistics::Descriptive Perl 的统计模块




use strict;
use warnings;
use Statistics::Descriptive;

my @temp=qw/26 25 23 23 26 25 24 26 28 27 26 23 28 26 25 27 27 23 24 25/;

my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(\@temp);
my $mean = $stat->mean();#平均值
my $variance = $stat->variance();#方差
my $num = $stat->count();#data的数目
my $standard_deviation=$stat->standard_deviation();#标准差
my $sum=$stat->sum();#求和
my $min=$stat->min();#最小值
my $mindex=$stat->mindex();#最小值的index
my $max=$stat->max();#最大值
my $maxdex=$stat->maxdex();#最大值的index
my $range=$stat->sample_range();#最小值到最大值



print "Number of Values = $num\n",
      "Mean = $mean\n",
      "Variance = $variance\n",
	  "standard_deviation = $standard_deviation\n",
	  "sum =$sum\n",
	  "min =$min\n",
	  "mindex=$mindex\n",
	  "max=$max\n",
	  "maxdex=$maxdex\n",
	  "range=$range\n";



C:\Windows\system32\cmd.exe /c perl "C:\Users\GRC\Desktop\a.pl"
Number of Values = 20
Mean = 25.35
Variance = 2.66052631578944
standard_deviation = 1.63111198750712
sum =507
min =23
mindex=17
max=28
maxdex=12
range=5
Hit any key to close this window...


你可能感兴趣的:(perl Statistics::Descriptive Perl 的统计模块)