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

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})
主站蜘蛛池模板: 太原市| 安远县| 衡阳市| 无锡市| 栾川县| 响水县| 根河市| 中宁县| 旺苍县| 遂平县| 姜堰市| 外汇| 武山县| 彩票| 吴桥县| 拉孜县| 九江县| 井研县| 南岸区| 启东市| 巫山县| 承德市| 内乡县| 哈密市| 长治市| 北安市| 新津县| 泾川县| 镶黄旗| 大洼县| 利津县| 佛山市| 会宁县| 界首市| 敖汉旗| 彭泽县| 依兰县| 庄河市| 镇江市| 馆陶县| 丰台区|