简体   繁体   English

在Gonum示例应用程序中声明类型

[英]Declaring types in Go for a sample gonum application

Being an ardent fan of numpy, I was pleased to discover that a library for golang was in progress. 作为numpy的狂热爱好者,我很高兴发现golang的库正在开发中。 I wrote a small test program, based heavily on the documentation, that looks like the following: 我主要根据文档编写了一个小型测试程序,如下所示:

package main

import (

    "fmt"
    "math"
    "gonum.org/v1/gonum/stat"
)

func main() {

    xs := []float64 {

        23.32, 44.32, 100.12, 191.90,
        23.22, 90.21, 12.22, 191.21,
        1.21, 12.21, 34.23, 91.02,
    }

    variance := stat.Variance(xs)
    fmt.Printf("Data: %v\n", xs)

    stddev := math.Sqrt(variance)

    fmt.Printf("Standard deviation: %d\n\n", stddev)
}

When I attempted to build the program, I noticed the following compiler error: 当我尝试构建程序时,我注意到以下编译器错误:

C:\>go build hello.go
# command-line-arguments
.hello.go:19:30: not enough arguments in call to stat.Variance
        have ([]float64)
        want ([]float64, []float64)

Any advice would be most appreciated. 任何建议将不胜感激。

Thank you. 谢谢。

stat.Variance expects two parameters of type []float64 of the same length: stat.Variance期望[]float64类型的两个参数的长度相同:

func Variance(x, weights []float64) float64

You are missing the weights parameter. 您缺少weights参数。 You can pass nil as the second parameter of stat.Variance function if you wants to set all the weights of the random variables to 1. 如果要将随机变量的所有权重设置为1,可以将nil作为stat.Variance函数的第二个参数传递。

stat Package Documentation 统计软件包文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM