March 2020
Intermediate to advanced
406 pages
8h 39m
English
While manipulating matrices, we may want to multiply all of the values within a matrix by a scalar value.
We can represent this in Go with the following code:
package mainimport ( "fmt" "gonum.org/v1/gonum/mat")func main() { a := mat.NewDense(3, 3, []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}) a.Scale(4, a) // Scale matrix by 4 matrixPrint(a)}func matrixPrint(m mat.Matrix) { formattedMatrix := mat.Formatted(m, mat.Prefix(""), mat.Squeeze()) fmt.Printf("%v\n", formattedMatrix)}
This code produces the following results:

Here, we can see that each element in our matrix has been scaled by 4, thus providing an executed example of ...
Read now
Unlock full access