remove ginext/mongoext (no-dep lib)
This commit is contained in:
41
mathext/statistics.go
Normal file
41
mathext/statistics.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package mathext
|
||||
|
||||
func Sum(v []float64) float64 {
|
||||
total := float64(0)
|
||||
for _, v := range v {
|
||||
total += v
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func Mean(v []float64) float64 {
|
||||
return Sum(v) / float64(len(v))
|
||||
}
|
||||
|
||||
func Median(v []float64) float64 {
|
||||
if len(v)%2 == 1 {
|
||||
return v[len(v)/2]
|
||||
} else {
|
||||
return (v[len(v)/2-1] + v[len(v)/2]) / float64(2)
|
||||
}
|
||||
}
|
||||
|
||||
func Min(v []float64) float64 {
|
||||
r := v[0]
|
||||
for _, val := range v {
|
||||
if val < r {
|
||||
r = val
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func Max(v []float64) float64 {
|
||||
r := v[0]
|
||||
for _, val := range v {
|
||||
if val > r {
|
||||
r = val
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
Reference in New Issue
Block a user