Sha256: 4c217c2d026066d672702a1ac77eb268e440f17677704a683dda9c44e0779fa1
Contents?: true
Size: 486 Bytes
Versions: 2
Compression:
Stored size: 486 Bytes
Contents
class Array def mean self.sum.to_f / self.length end def arithmetric_mean self.mean end def geometric_mean self.product.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.4 | lib/rstat/core_ext/array/mean.rb |
rstat-0.0.3 | lib/rstat/core_ext/array/mean.rb |