Documentation ¶
Overview ¶
Package sliceutil provides a collection of utility functions for Go slices.
It includes functions for filtering, mapping, and reducing slices, as well as generating descriptive statistics for numerical slices.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
Filter returns a new slice containing only the elements in the input slice s for which the specified function f is true.
func Map ¶
Map returns a new slice that contains each of the elements of the input slice s mutated by the specified function.
Types ¶
type DescStats ¶ added in v1.80.0
type DescStats[V typeutil.Number] struct { // Count is the total number of items in the data set. Count int `json:"count"` // Entropy computes the Shannon entropy of a distribution. Entropy float64 `json:"entropy"` // ExKurtosis is the population excess kurtosis of the data set. // The kurtosis is defined by the 4th moment of the mean divided by the squared variance. // The excess kurtosis subtracts 3.0 so that the excess kurtosis of the normal distribution is zero. ExKurtosis float64 `json:"exkurtosis"` // Max is the maximum value of the data. Max V `json:"max"` // MaxID is the index (key) of the Max malue in a data set. MaxID int `json:"maxid"` // Mean or Average is a central tendency of the data. Mean float64 `json:"mean"` // MeanDev is the Mean Deviation or Mean Absolute Deviation. // It is an average of absolute differences between each value in the data, and the average of all values. MeanDev float64 `json:"meandev"` // Median is the value that divides the data into 2 equal parts. // When the data is sorted, the number of terms on the left and right side of median is the same. Median float64 `json:"median"` // Min is the minimal value of the data. Min V `json:"min"` // MinID is the index (key) of the Min malue in a data set. MinID int `json:"minid"` // Mode is the term appearing maximum time in data set. // It is the term that has the highest frequency. Mode V `json:"mode"` // ModeFreq is the frequency of the Mode value. ModeFreq int `json:"modefreq"` // Range is the difference between the highest (Max) and lowest (Min) value. Range V `json:"range"` // Skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable about its mean. // Provides the adjusted Fisher-Pearson standardized moment coefficient. Skewness float64 `json:"skewness"` // StdDev is the Standard deviation of the data. // It measures the average distance between each quantity and mean. StdDev float64 `json:"stddev"` // Sum of all the values in the data. Sum V `json:"sum"` // Variance is a square of average distance between each quantity and Mean. Variance float64 `json:"variance"` }
DescStats contains descriptive statistics items for a data set.
func Stats ¶ added in v1.80.0
Stats returns descriptive statistics parameters to summarize the input data set.
Example ¶
Output: Count: 12 Entropy: 2.302 ExKurtosis: -1.910 Max: 83 MaxID: 1 Mean: 50.500 MeanDev: 0.000 Median: 45.000 Min: 13 MinID: 2 Mode: 83 ModeFreq: 4 Range: 70 Skewness: -0.049 StdDev: 30.285 Sum: 606 Variance: 917.182
Click to show internal directories.
Click to hide internal directories.