1 Star 4 Fork 12

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ndarray_range.go 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-06-14 09:33 . 收敛ScopeLimit到gox工具库
package stat
import (
"gitee.com/quant1x/gox/api"
"golang.org/x/exp/slices"
"reflect"
)
func (self NDArray[T]) IndexOf(index int, opt ...any) any {
if index < 0 {
index = self.Len() + index
} else if index >= self.Len() {
index = self.Len() - 1
}
var __optInplace = false
if len(opt) > 0 {
// 第一个参数为是否替换
if _opt, ok := opt[0].(bool); ok {
__optInplace = _opt
}
}
value := self[index]
if __optInplace {
mv := reflect.ValueOf(self.Values())
return mv.Index(index)
}
return value
}
func (self NDArray[T]) Subset(start, end int, opt ...any) Series {
// 默认不copy
var __optCopy = false
if len(opt) > 0 {
// 第一个参数为是否copy
if _cp, ok := opt[0].(bool); ok {
__optCopy = _cp
}
}
values := []T(self)
rows := self.Len()
vvs := values[start:end]
if __optCopy && rows > 0 {
vvs = slices.Clone(vvs)
}
var d Series
d = NDArray[T](vvs)
return d
}
func (self NDArray[T]) Select(r api.ScopeLimit) Series {
start, end, err := r.Limits(self.Len())
if err != nil {
return nil
}
series := self.Subset(start, end+1)
return series
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.0.3

搜索帮助