使用以下代码来解析数据并计算差值:

package main

import (
	"fmt"
)

func main() {
	data := [][]interface{}{{"SIL", []float64{0, 0.3288888888888889}}, {"我", []float64{0.3288888888888889, 0.4333786848072563}}, {"们", []float64{0.4333786848072563, 0.5843083900226758}}, {"三", []float64{0.5843083900226758, 0.8513378684807257}}, {"个", []float64{0.8513378684807257, 1.0951473922902495}}, {"SIL", []float64{1.0951473922902495, 1.2951473922902494}}}

	for _, item := range data {
		word := item[0].(string)
		start := item[1].([]float64)[0]
		end := item[1].([]float64)[1]

		fmt.Printf("[%s]的差值为%.4f\n", word, end-start)
	}
}

运行该代码会得到以下输出:

[SIL]的差值为0.3289
[我]的差值为0.1045
[们]的差值为0.1509
[三]的差值为0.2670
[个]的差值为0.2438
[SIL]的差值为0.2000

其中 [SIL] 的差值为 0.3289,即 0.3288888888888889 - 0

Golang 解析数据并计算差值:以 [][]interface{} 类型为例

原文地址: https://www.cveoy.top/t/topic/p0wE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录