duanmiaosi0150 2018-05-06 20:14
浏览 42
已采纳

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

Being an ardent fan of numpy, I was pleased to discover that a library for golang was in progress. 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
", xs)

    stddev := math.Sqrt(variance)

    fmt.Printf("Standard deviation: %d

", 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.

  • 写回答

1条回答 默认 最新

  • dtlygweb2017 2018-05-06 20:20
    关注

    stat.Variance expects two parameters of type []float64 of the same length:

    func Variance(x, weights []float64) float64
    

    You are missing the weights parameter. 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.

    stat Package Documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图