- 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})
- 極簡(jiǎn)算法史:從數(shù)學(xué)到機(jī)器的故事
- Mastering Objectoriented Python
- AngularJS Web Application Development Blueprints
- Unity Virtual Reality Projects
- Instant Typeahead.js
- Python爬蟲(chóng)開(kāi)發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Linux網(wǎng)絡(luò)程序設(shè)計(jì):基于龍芯平臺(tái)
- UML 基礎(chǔ)與 Rose 建模案例(第3版)
- Mastering JavaScript High Performance
- 基于Struts、Hibernate、Spring架構(gòu)的Web應(yīng)用開(kāi)發(fā)
- Rust游戲開(kāi)發(fā)實(shí)戰(zhàn)
- Django 3.0應(yīng)用開(kāi)發(fā)詳解
- Visual Studio Code 權(quán)威指南
- 創(chuàng)意UI:Photoshop玩轉(zhuǎn)APP設(shè)計(jì)