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

  • Machine Learning With Go
  • Daniel Whitenack
  • 181字
  • 2021-07-08 10:37:31

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})
主站蜘蛛池模板: 达日县| 竹山县| 逊克县| 河东区| 斗六市| 富蕴县| 达孜县| 津市市| 连云港市| 青冈县| 华宁县| 旌德县| 广饶县| 象山县| 汶川县| 田阳县| 绥化市| 申扎县| 阿拉善盟| 白河县| 庆元县| 昂仁县| 中阳县| 遂宁市| 侯马市| 博爱县| 盈江县| 永安市| 晴隆县| 沈阳市| 盐山县| 绩溪县| 本溪市| 凤城市| 清水河县| 金华市| 六安市| 玉山县| 龙州县| 安陆市| 闽侯县|