How to use the sparse function from mathjs

Find comprehensive JavaScript mathjs.sparse code examples handpicked from public code repositorys.

22
23
24
25
26
27
28
29
30
31
//   - sum_j_export(v_ij) * x_i
// Note that exports cancel out.

// We wish to solve Ax = b
var n = validCountries.length;
var A = mathjs.sparse().resize([n, n]);
var b = mathjs.zeros(n);

validCountries.forEach(function (country, i) {
    A.set([i, i], country.totalProduction + country.totalImport);
fork icon799
star icon0
watch icon2

+ 4 other calls in file

30
31
32
33
34
35
36
37
38
39
                                                  K = this.K,
          B = this.B
         );

// Create a sparse matrix with initial data and the 'number' datatype.
this.docIndex = math.sparse(bm25.buildMatr(), 
                                                                         'number'
                                                                        );

// Create a reverse index for fast keyword search.
fork icon8
star icon27
watch icon3

27
28
29
30
31
32
33
34
35
36
let bm25 = new Bm25(corpusMatr = this.docArray.map(chunkFilterStem),
                    K = this.K,
                    B = this.B);

// Creates a sparse matrix with initial data; number datatype.
this.docIndex = math.sparse(bm25.buildMatr(), 'number');

// Creates a reverse index for fast keyword search.
this.termIndex = bm25.getTerms();
};
fork icon8
star icon0
watch icon2

12
13
14
15
16
17
18
19
20
21

function load_image(raw_image, padding){
  let rows = raw_image.split("\r\n");
  let column_count = rows[0].length;

  let matrix = math.sparse();
  matrix.resize([column_count + 2*padding, rows.length + 2*padding], false);

  for(let x = 0; x < rows.length; x++){
    let row = rows[x];
fork icon0
star icon0
watch icon2

+ 5 other calls in file