官术网_书友最值得收藏!

Vectors

A vector is an ordered collection of numbers arranged in either a row (left to right) or column (up and down). Each of the numbers in a vector is called a component. This might be, for example, a collection of numbers that represents our company sales, or it might be a collection of numbers representing temperatures.

It's, of course, natural for us to use Go slices to represent these ordered collections of data, as follows:

// Initialize a "vector" via a slice.
var myvector []float64

// Add a couple of components to the vector.
myvector = append(myvector, 11.0)
myvector = append(myvector, 5.2)

// Output the results to stdout.
fmt.Println(myvector)

Slices are indeed ordered collections. However, they don't really represent the concept of rows or columns, and we would still need to work out various vector operations on top of slices. Thankfully, on the vector operation side, gonum provides gonum.org/v1/gonum/floats to operate on slices of float64 values and gonum.org/v1/gonum/mat, which, along with matrices, provides a Vector type (with corresponding methods):

// Create a new vector value.
myvector := mat.NewVector(2, []float64{11.0, 5.2})
主站蜘蛛池模板: 马山县| 瑞昌市| 嘉定区| 漳平市| 顺义区| 华蓥市| 江阴市| 紫阳县| 平阳县| 湛江市| 深州市| 靖宇县| 安岳县| 三台县| 历史| 襄汾县| 仪征市| 云和县| 泰兴市| 东宁县| 新泰市| 洛阳市| 宿迁市| 巴林右旗| 黑龙江省| 永春县| 固阳县| 库尔勒市| 囊谦县| 黄龙县| 白城市| 凯里市| 南召县| 盘山县| 青铜峡市| 平南县| 新民市| 吴堡县| 尚志市| 平武县| 天祝|