Sha256: 81f731b4b8c970855ee8d03b880c2aa8a8c378016a460950fb948dd2c7ba3567
Contents?: true
Size: 496 Bytes
Versions: 2
Compression:
Stored size: 496 Bytes
Contents
class Array def mean self.inject(:+).to_f / self.length end def arithmetric_mean self.mean end def geometric_mean self.inject(:*).to_f ** (1.0 / self.length) end def harmonic_mean self.length / self.map{ |x| 1.0 / x }.inject{ |sum, x| sum + x }.to_f end def quadratic_mean self.power_mean(2) end def power_mean(p = 1) ((1.0 / self.length) * self.map{ |x| x ** p }.inject{ |sum, x| sum + x }.to_f) ** (1.0 / p) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rstat-0.0.2 | lib/rstat/core_ext/array/mean.rb |
rstat-0.0.1 | lib/rstat/core_ext/array/mean.rb |