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

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})
主站蜘蛛池模板: 许昌市| 阿勒泰市| 阿拉善盟| 怀化市| 新乡县| 溧阳市| 凤凰县| 南华县| 镇江市| 木里| 岐山县| 高唐县| 侯马市| 双牌县| 施甸县| 泰顺县| 布拖县| 胶南市| 潢川县| 乌兰浩特市| 邯郸县| 锡林浩特市| 南江县| 遵义市| 靖远县| 乌兰察布市| 辽中县| 南康市| 叶城县| 抚松县| 潜山县| 诸城市| 若尔盖县| 鄂托克前旗| 扎鲁特旗| 涟水县| 天台县| 丽水市| 宁陕县| 南岸区| 呼玛县|