Back-end components after component sharing - a well-tested and comprehensive Golang statistics library/package/module stats...

Backend components after component sharing - a well-tested and comprehensive Golang statistics library/package/module stats

background

Recently, we are exploring various common components and tools on the front-end, back-end, and system side, and reorganize some of the common components to form a standardized component topic, which will later include some commonly used components in various languages. Welcome everyone to continue to pay attention.

Component Basic Information

content

In this section we share a well-tested and comprehensive Golang statistics library/package/module stats with no dependencies.
The specific usage is as follows:
1. Installation

go get github.com/montanaflynn/stats

2. Examples

// start with some source data to use
data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}

// you could also use different types like this
// data := stats.LoadRawData([]int{1, 2, 3, 4, 5})
// data := stats.LoadRawData([]interface{}{1.1, "2", 3})
// etc...

median, _ := stats.Median(data)
fmt.Println(median) // 3.65

roundedMedian, _ := stats.Round(median, 0)
fmt.Println(roundedMedian) // 4

Specific API documentation can be found on GoDoc.org or pkg.go.dev .

This article declares:
88x31.png
Creative Commons License
This work is licensed by CN Hua Shao under the Creative Commons Attribution-Noncommercial 4.0 International License.

Guess you like

Origin blog.csdn.net/csde12/article/details/125717278