Documentation
¶
Overview ¶
Package vectors provides basic vector operations.
Example 1 ¶
Summing vectors and calculating distances:
a, b, c, d := {some vectors}
Giving a nil result vector to Sum() allocates a new result, and thus does not change a, b, c or d.
dist := L2(Sum(nil, a, b), Sum(nil, c, d))
Giving a non-nil result vector to Sum() changes it. The following call will give the same distance but will modify a and c.
dist := L2(Sum(a, b), Sum(c, d))
Example 2 ¶
Creating a vector of -1's of length 10:
v := Mul(Ones(10), -1)
Index ¶
- func Add(a []float64, b ...[]float64) []float64
- func Copy(a []float64) []float64
- func Dot(a, b []float64) float64
- func L1(a, b []float64) float64
- func L2(a, b []float64) float64
- func Lp(p int) func([]float64, []float64) float64
- func Mul(a []float64, m float64) []float64
- func Norm(a []float64) float64
- func Ones(n int) []float64
- func Sub(a []float64, b ...[]float64) []float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lp ¶
Lp returns an Lp distance function. Lp is calculated as follows:
Lp(v) = the p'th root of sum_i(v[i]^p)
For convenience, L1 (Manhattan)and L2 (Euclidean) are prepared package variables.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.