1 Star 4 Fork 13

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mean.go 869 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-06-06 07:34 . 更新依赖库版本
package stat
import (
"gitee.com/quant1x/gox/num"
"gitee.com/quant1x/gox/num/num32"
)
// Mean 求均值
func Mean[T Number](x []T) T {
return unaryOperations1[T](x, num32.Mean, num.Mean, __mean_go[T])
}
func __mean_go[T Number](x []T) T {
return __sum(x) / T(len(x))
}
func Mean2[T BaseType](x []T) T {
var d any
switch vs := any(x).(type) {
case []float32:
d = Mean(vs)
case []float64:
d = Mean(vs)
case []int:
d = Mean(vs)
case []int8:
d = Mean(vs)
case []int16:
d = Mean(vs)
case []int32:
d = Mean(vs)
case []int64:
d = Mean(vs)
case []uint:
d = Mean(vs)
case []uint8:
d = Mean(vs)
case []uint16:
d = Mean(vs)
case []uint32:
d = Mean(vs)
case []uint64:
d = Mean(vs)
case []uintptr:
d = Mean(vs)
//case []string:
// d = __max_go(vs)
default:
// 其它类型原样返回
panic(Throw(any(x)))
}
return d.(T)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.2.2

搜索帮助