Documentation ¶
Index ¶
- Constants
- Variables
- func Abs[T StatType](x []T) []T
- func Align[T MoveType](x []T, a T, dLen int) []T
- func AnyToFloat32(v any) float32
- func AnyToFloat64(v any) float64
- func AnyToInt64(v any) int64
- func AnyToSlice[T StatType](A any, n int) []T
- func AnyToString(v any) string
- func ArgMax[T Number](v []T) int
- func ArgMin[T Number](v []T) int
- func CumSum[T StatType](f []T) []T
- func DTypeIsNaN(d DType) bool
- func Fill[T StatType | ~string](v []T, d T, args ...any) (rows []T)
- func FillNa[T StatType | ~string](v []T, args ...any) []T
- func Float32IsNaN(f float32) bool
- func Float64IsNaN(f float64) bool
- func IsEmpty(s string) bool
- func LinearRegression(x, y, weights []float64, origin bool) (alpha, beta float64)
- func Max[T Float](f []T) T
- func Maximum[T Float](f1, f2 []T) []T
- func Maximum_GO[T Float](f1, f2 []T) []T
- func Mean[T StatType](x []T) T
- func Min[T Float](f []T) T
- func Minimum[T Float](f1, f2 []T) []T
- func Minimum_GO[T Float](f1, f2 []T) []T
- func ParseFloat32(s string, v any) float32
- func ParseFloat64(s string, v any) float64
- func ParseInt64(s string, v any) int64
- func Repeat[T StatType](f T, n int) []T
- func Reverse[S ~[]E, E any](s S) S
- func Sequence[T StatType](n int) []T
- func SliceToFloat32(v any) []float32
- func SliceToFloat64(v any) []float64
- func Sqrt[T StatType](v []T) []T
- func Std[T Float](f []T) T
- func Std_TODO[T Float](f []T) T
- func StringIsNaN(s string) bool
- func Sub[T StatType](x []T, y any) []T
- func Sum[T StatType](f []T) T
- func Where[T StatType](condition []T, x, y []T) []T
- func Zeros()
- type Array
- type BigFloat
- type DType
- type Float
- type Frame
- type GenericType
- type Int
- type Integer
- type MoveType
- type NDArray
- type Number
- type Number16
- type Number32
- type Number64
- type Number8
- type StatType
Constants ¶
const ( Nil2Bool = false // 空指针转bool BoolNaN = false // bool 无效值 True2Bool = true // true转bool False2Bool = false // false 转bool True2Float32 float32 = float32(1) // true转float32 False2Float32 float32 = float32(0) // false转float32 StringBad2Bool = false // 字符串解析bool异常 StringTrue2Bool = true // 字符串true转bool StringFalse2Bool = false // 字符串false转bool )
const ( MaxFloat32 = float32(math.MaxFloat32) // float32最大值 MinFloat32 = float32(math.SmallestNonzeroFloat32) // float32最小值 StringTrue2Float32 float32 = float32(1) // 字符串true转float32 StringFalse2Float32 float32 = float32(0) // 字符串false转float32 )
const ( MaxFloat64 float64 = float64(math.MaxFloat64) // float64最大值 MinFloat64 float64 = float64(math.SmallestNonzeroFloat64) // float64最小值 True2Float64 float64 = float64(1) // true转float64 False2Float64 float64 = float64(0) // false转float64 StringNil2Float float64 = float64(0) // deprecated: 字符串空指针转float64 StringBad2Float float64 = float64(0) // deprecated: 字符串解析float64异常 StringTrue2Float64 float64 = float64(1) // 字符串true转float64 StringFalse2Float64 float64 = float64(0) // 字符串false转float64 )
const ( MaxInt64 = int64(math.MaxInt64) MinInt64 = int64(math.MinInt64) Nil2Int64 = int64(0) // 空指针转int64 Int64NaN = int64(0) // int64 无效值 True2Int64 = int64(1) // true转int64 False2Int64 = int64(0) // false 转int64 StringBad2Int64 = int64(0) // 字符串解析int64异常 StringTrue2Int64 = int64(1) // 字符串true转int64 StringFalse2Int64 = int64(0) // 字符串false转int64 )
const ( StringNaN = "NaN" // 字符串NaN Nil2String = "NaN" // nil指针转string True2String = "true" // true转string False2String = "false" // false转string )
Variables ¶
var ( // Nil2Float64 nil指针转换float64 Nil2Float64 = float64(0) // Nil2Float32 nil指针转换float32 Nil2Float32 = float32(0) DTypeNaN = DType(0) )
var ( // 不支持的类型 ErrUnsupportedType = exception.New(errorTypeBase+0, "Unsupported type") )
var ( // IgnoreParseExceptions 忽略解析异常 IgnoreParseExceptions bool = true )
var ( // PossibleNaOfString 有可能出现的NaN字符串的全部选项 PossibleNaOfString = []string{"NA", "NaN", "nan", "<nil>"} )
Functions ¶
func AnyToFloat32 ¶ added in v0.6.4
func AnyToFloat64 ¶ added in v0.6.4
func ArgMax ¶ added in v0.6.4
ArgMax Returns the indices of the maximum values along an axis. 返回轴上最大值的索引
func ArgMin ¶ added in v0.6.4
ArgMin Returns the indices of the minimum values along an axis. 返回轴上最小值的索引
func Fill ¶ added in v0.6.4
Fill 填充
Fill NA/NaN values using the specified method. Parameters ---------- value : scalar, dict, Series, or DataFrame Value to use to fill holes (e.g. 0), alternately a dict/Series/DataFrame of values specifying which value to use for each index (for a Series) or column (for a DataFrame). Values not in the dict/Series/DataFrame will not be filled. This value cannot be a list. method : {{'backfill', 'bfill', 'pad', 'ffill', None}}, default None Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use next valid observation to fill gap. axis : {axes_single_arg} Axis along which to fill missing values. For `Series` this parameter is unused and defaults to 0. inplace : bool, default False [√] If True, fill in-place. Note: this will modify any other views on this object (e.g., a no-copy slice for a column in a DataFrame). limit : int, default None If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None. downcast : dict, default is None A dict of item->dtype of what to downcast if possible, or the string 'infer' which will try to downcast to an appropriate equal type (e.g. float64 to int64 if possible). Returns ------- []T or None
func LinearRegression ¶
LinearRegression 线性回归
func Maximum ¶ added in v0.6.4
func Maximum[T Float](f1, f2 []T) []T
Maximum AVX2版本, 两个序列横向比较最大值 TODO:print(np.maximum(1.4, np.nan)) 输出nan
func Maximum_GO ¶ added in v0.6.4
func Maximum_GO[T Float](f1, f2 []T) []T
Maximum_GO go版本, 两个序列横向比较最大值
func Minimum_GO ¶ added in v0.6.4
func Minimum_GO[T Float](f1, f2 []T) []T
Minimum_GO go版本 两个序列横向比较最大值
func ParseFloat32 ¶ added in v0.6.4
ParseFloat32 字符串转float32
func ParseFloat64 ¶ added in v0.6.4
ParseFloat64 字符串转float64 任意组合的nan字符串都会被解析成NaN
func ParseInt64 ¶ added in v0.6.4
ParseInt64 解析int字符串, 尝试解析10进制和16进制
func SliceToFloat32 ¶ added in v0.6.4
SliceToFloat32 any输入只能是一维slice或者数组
func SliceToFloat64 ¶ added in v0.6.4
SliceToFloat64 any输入只能是一维slice或者数组
func Std_TODO ¶ added in v0.6.4
func Std_TODO[T Float](f []T) T
Std_TODO StdDev 这个版本有bug, gonum计算的std不对 TODO: 于总来解决
Types ¶
type DType ¶ added in v0.6.4
type DType = float64
func Median ¶ added in v0.6.4
Median returns median value of series. Linear interpolation is used for odd length. TODO:未加验证, 未加速
func PolyFit ¶ added in v0.6.4
PolyFit Least squares polynomial fit.
.. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`transition guide </reference/routines.polynomials>`. Fit a polynomial ``p(x) = p[0] * x**deg + ... + p[deg]`` of degree `deg` to points `(x, y)`. Returns a vector of coefficients `p` that minimises the squared error in the order `deg`, `deg-1`, ... `0`. The `Polynomial.fit <numpy.polynomial.polynomial.Polynomial.fit>` class method is recommended for new code as it is more stable numerically. See the documentation of the method for more information. Parameters ---------- x : array_like, shape (M,) x-coordinates of the M sample points ``(x[i], y[i])``. y : array_like, shape (M,) or (M, K) y-coordinates of the sample points. Several data sets of sample points sharing the same x-coordinates can be fitted at once by passing in a 2D-array that contains one dataset per column. deg : int Degree of the fitting polynomial Returns ------- p : ndarray, shape (deg + 1,) or (deg + 1, K) Polynomial coefficients, highest power first. If `y` was 2-D, the coefficients for `k`-th data set are in ``p[:,k]``. residuals, rank, singular_values, rcond These values are only returned if ``full == True`` - residuals -- sum of squared residuals of the least squares fit - rank -- the effective rank of the scaled Vandermonde coefficient matrix - singular_values -- singular values of the scaled Vandermonde coefficient matrix - rcond -- value of `rcond`. For more details, see `numpy.linalg.lstsq`. Warns ----- RankWarning The rank of the coefficient matrix in the least-squares fit is deficient. The warning is only raised if ``full == False``. The warnings can be turned off by >>> import warnings >>> warnings.simplefilter('ignore', np.RankWarning) See Also -------- polyval : Compute polynomial values. linalg.lstsq : Computes a least-squares fit. scipy.interpolate.UnivariateSpline : Computes spline fits. Notes ----- The solution minimizes the squared error .. math:: E = \\sum_{j=0}^k |p(x_j) - y_j|^2 in the equations:: x[0]**n * p[0] + ... + x[0] * p[n-1] + p[n] = y[0] x[1]**n * p[0] + ... + x[1] * p[n-1] + p[n] = y[1] ... x[k]**n * p[0] + ... + x[k] * p[n-1] + p[n] = y[k] The coefficient matrix of the coefficients `p` is a Vandermonde matrix. `polyfit` issues a `RankWarning` when the least-squares fit is badly conditioned. This implies that the best fit is not well-defined due to numerical error. The results may be improved by lowering the polynomial degree or by replacing `x` by `x` - `x`.mean(). The `rcond` parameter can also be set to a value smaller than its default, but the resulting fit may be spurious: including contributions from the small singular values can add numerical noise to the result. Note that fitting polynomial coefficients is inherently badly conditioned when the degree of the polynomial is large or the interval of sample points is badly centered. The quality of the fit should always be checked in these cases. When polynomial fits are not satisfactory, splines may be a good alternative. References ---------- .. [1] Wikipedia, "Curve fitting", https://en.wikipedia.org/wiki/Curve_fitting .. [2] Wikipedia, "Polynomial interpolation", https://en.wikipedia.org/wiki/Polynomial_interpolation .. [3] numpy.polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False) https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html Examples -------- >>> import warnings >>> x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) >>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) >>> z = np.polyfit(x, y, 3) >>> z array([ 0.08703704, -0.81349206, 1.69312169, -0.03968254]) # may vary
func PolyVal ¶ added in v0.6.4
PolyVal
Evaluate a polynomial at specific values. .. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`transition guide </reference/routines.polynomials>`. If `p` is of length N, this function returns the value: ``p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1]`` If `x` is a sequence, then ``p(x)`` is returned for each element of ``x``. If `x` is another polynomial then the composite polynomial ``p(x(t))`` is returned. Parameters
----------
p : array_like or poly1d object 1D array of polynomial coefficients (including coefficients equal to zero) from highest degree to the constant term, or an instance of poly1d. x : array_like or poly1d object A number, an array of numbers, or an instance of poly1d, at which to evaluate `p`. Returns
-------
values : ndarray or poly1d If `x` is a poly1d instance, the result is the composition of the two polynomials, i.e., `x` is "substituted" in `p` and the simplified result is returned. In addition, the type of `x` - array_like or poly1d - governs the type of the output: `x` array_like => `values` array_like, `x` a poly1d object => `values` is also. See Also -------- poly1d: A polynomial class. Notes ----- Horner's scheme [1]_ is used to evaluate the polynomial. Even so, for polynomials of high degree the values may be inaccurate due to rounding errors. Use carefully. If `x` is a subtype of `ndarray` the return value will be of the same type. References ---------- .. [1] I. N. Bronshtein, K. A. Semendyayev, and K. A. Hirsch (Eng. trans. Ed.), *Handbook of Mathematics*, New York, Van Nostrand Reinhold Co., 1985, pg. 720. Examples -------- >>> np.polyval([3,0,1], 5) # 3 * 5**2 + 0 * 5**1 + 1 76 >>> np.polyval([3,0,1], np.poly1d(5)) poly1d([76]) >>> np.polyval(np.poly1d([3,0,1]), 5) 76 >>> np.polyval(np.poly1d([3,0,1]), np.poly1d(5)) poly1d([76])
type GenericType ¶ added in v0.6.4
GenericType Series支持的所有类型
Source Files ¶
- abs.go
- align.go
- argmax.go
- argmin.go
- array.go
- builtin.go
- cumsum.go
- errors.go
- fillna.go
- gonum.go
- max.go
- maximum.go
- mean.go
- median.go
- min.go
- minimum.go
- params.go
- polynomial.go
- repeat.go
- reverse.go
- sqrt.go
- stddev.go
- sub.go
- sum.go
- type.go
- type_bool.go
- type_dtype.go
- type_float32.go
- type_float64.go
- type_int64.go
- type_string.go
- unsafe.go
- where.go
- zeros.go