1 Star 4 Fork 13

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ndarray_fromnumeric.go 5.35 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-02-18 15:26 . !68修订部分问题, 清理package
package stat
import "github.com/viterin/vek"
func (self NDArray[T]) ArgMax() int {
return ArgMax2(self)
}
func (self NDArray[T]) ArgMin() int {
return ArgMin2(self)
}
func (self NDArray[T]) Add(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 := Add(a, b)
return NDArray[DType](s)
}
func (self NDArray[T]) Sub(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 := Sub(a, b)
return NDArray[DType](s)
}
func (self NDArray[T]) Mul(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 := Mul(a, b)
return NDArray[DType](s)
}
func (self NDArray[T]) Div(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 := Div(a, b)
return NDArray[DType](s)
}
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]) Gt(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 := vek.Gt(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) Gte(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 := vek.Gte(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) Lt(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 := vek.Lt(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) Lte(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 := vek.Lte(a, b)
return NDArray[bool](s)
}
func (self NDArray[T]) And(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)
default:
panic(Throw(x))
}
a := ToBool(self)
s := vek.And(a, b)
return NDArray[bool](s)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.7.0

搜索帮助