1 Star 4 Fork 13

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ndarray_logic.go 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-07-29 17:19 . 增加逻辑操作OR
package stat
import "gitee.com/quant1x/gox/num"
func (self NDArray[T]) Logic(f func(idx int, v any) bool) []bool {
d := make([]bool, self.Len())
for i, v := range self {
d[i] = f(i, v)
}
return d
}
func (self NDArray[T]) Eq(x any) Series {
length := self.Len()
var b []DType
switch sx := x.(type) {
case Series:
b = sx.DTypes()
case int:
b = Repeat[DType](DType(sx), length)
case DType:
b = Repeat[DType](sx, length)
//case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, uintptr, float32, float64:
// b = Repeat[DType](DType(sx), length)
case []DType:
b = Align[DType](sx, DTypeNaN, length)
default:
panic(Throw(x))
}
a := self.DTypes()
s := Equal(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) V1Gt(x any) Series {
length := self.Len()
var b []DType
switch sx := x.(type) {
case Series:
b = sx.DTypes()
case int:
b = Repeat[DType](DType(sx), length)
case DType:
b = Repeat[DType](sx, length)
//case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, uintptr, float32, float64:
// b = Repeat[DType](DType(sx), length)
case []DType:
b = Align[DType](sx, DTypeNaN, length)
default:
panic(Throw(x))
}
a := self.DTypes()
s := num.Gt(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) Gt(x any) Series {
values := self.Values().([]T)
bs := Gt(values, x)
return NDArray[bool](bs)
}
func (self NDArray[T]) Gte(x any) Series {
values := self.Values().([]T)
bs := Gte(values, x)
return NDArray[bool](bs)
}
func (self NDArray[T]) Lt(x any) Series {
values := self.Values().([]T)
bs := Lt(values, x)
return NDArray[bool](bs)
}
func (self NDArray[T]) Lte(x any) Series {
values := self.Values().([]T)
bs := Lte(values, x)
return NDArray[bool](bs)
}
func (self NDArray[T]) And(x any) Series {
values := self.Values().([]T)
bs := And(values, x)
return NDArray[bool](bs)
}
func (self NDArray[T]) V1And(x any) Series {
length := self.Len()
var b []bool
switch sx := x.(type) {
case Series:
b = ToBool(sx)
case int:
b = Repeat[bool](integer2Bool(sx), length)
case DType:
b = Repeat[bool](integer2Bool(sx), length)
//case int8, uint8, int16, uint16, int32, uint32, int64, uint64, int, uint, uintptr, float32, float64:
// b = Repeat[DType](DType(sx), length)
case []DType:
b = __NumberToBool_S(sx)
case []bool:
b = sx
default:
panic(Throw(x))
}
a := ToBool(self)
s := V1And(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) Or(x any) Series {
values := self.Values().([]T)
bs := Or(values, x)
return NDArray[bool](bs)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.2.2

搜索帮助