March 2019
Intermediate to advanced
336 pages
9h 9m
English
The main method creates the sparse matrix by invoking the NewSparseMatrix method. The values are set in cells (1, 1) and (1, 3). The sparse matrix and the number of non-zero cells are printed:
// main methodfunc main() { var sparseMatrix *SparseMatrix sparseMatrix = NewSparseMatrix(3, 3) sparseMatrix.SetValue(1, 1, 2.0) sparseMatrix.SetValue(1, 3, 3.0) fmt.Println(sparseMatrix) fmt.Println(sparseMatrix.NumNonZero())}
Run the following command to execute the sparse_matrix.go file:
go run sparse_matrix.go
The output is as follows:

Read now
Unlock full access