How to use the zeros function from mathjs

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

23
24
25
26
27
28
29
30
31
32
// 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);
    // Intern
fork icon799
star icon0
watch icon2

+ 4 other calls in file

4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
		res |= (1 << qubit);
	});
	return res;
}

var T = math.zeros([ 1 << totalQubits, 1 << totalQubits ]);

for(var elrow = 0; elrow < U.length; elrow++) {

	var rowmask = getElMask(elrow);
fork icon43
star icon207
watch icon14

+ 157 other calls in file

3
4
5
6
7
8
9
 * makes a mathjs sparse zero vector of the specified length.
 */
const math = require('mathjs');

module.exports = function(len_) {
    return math.zeros(len_, 1, 'sparse');
};
fork icon8
star icon27
watch icon3

27
28
29
30
31
32
33
34
35
36
  return matrix;
};

const makeAdjacencyMatrix = (nodes, n) => {
  // Graph
  const G = math.zeros(n, n, 'sparse');
  // Column sum
  const D = math.zeros(n, n, 'sparse');
  let index;
  let value;
fork icon4
star icon5
watch icon3

+ 5 other calls in file

147
148
149
150
151
152
153
154
155
156
precomputeParameters(sigmac = 16) {
  let i;

  const [L_centroid, A_centroid, B_centroid] = meshgrid(this.lRange, this.aRange, this.bRange)

  this.uniquePixels = math.zeros(this.numberOfColors, 3).toArray();
  let iIndex, iL, iA, iB;
  for (i = 0; i < this.numberOfColors; i++) {
    iIndex = this.indexMatrix[i];
    iL = L_centroid[iIndex[0]][iIndex[1]][iIndex[2]];
fork icon0
star icon5
watch icon2

+ 3 other calls in file

-2
fork icon1
star icon0
watch icon0

+ 3 other calls in file

190
191
192
193
194
195
196
197
198
199
    return [[]];
}

n = n || 0;
var dim = v.length + math.abs(n),
    mat = math.zeros(dim, dim),
    start = n > 0 ? [0, n] : [-n, 0],
    pos = start;

v.forEach(function(val) {
fork icon1
star icon0
watch icon15

73
74
75
76
77
78
79
80
81
82
    return math.dotMultiply(sigmoid(x), math.subtract(1, sigmoid(x)));
}

//Multiplies a column vector with a row vector because MathJS doesn't support tranposing 1 dimensional matrices
function outerProduct(x, y) {
    var z = math.zeros([math.size(x)[0], math.size(y)[0]]);
    for (var i = 0; i < math.size(x)[0]; i += 1) {
        for (var j = 0; j < math.size(y)[0]; j += 1) {
            var r = x[i] * y[j];
            z[i][j] = r;
fork icon0
star icon4
watch icon2

373
374
375
376
377
378
379
380
381
382
for (let index = 0; index < xList.length; index++) {
  const newX = xList[index];
  const newY = yList[index];
  const newZ = zList[index];

  const newData = mathjs.zeros(width * width)._data;
  const newCenter = { x: newX, y: newY, z: newZ };

  const startX = -floorHalf >> 1;
  const endX = floorHalf >> 1;
fork icon0
star icon0
watch icon1

+ 4 other calls in file

48
49
50
51
52
53
54
55
56
57

b=b-A*x0;

if (~arrayIsEmpty(beq)){
    let g = math.reshape(beq);
    g = math.zeros(math.size(beq));
}

paramsin[[2]]=b;
paramsin[[4]]=beq;
fork icon0
star icon0
watch icon0

65
66
67
68
69
70
71
72
73
74
const numTags = dimensions[0];
var PageRankVector = mathjs.ones(numTags);
// Initialize the PageRank vector to be a vector of 1/numTags
PageRankVector = mathjs.multiply(PageRankVector, 1/numTags);
// initialize the previous PageRank vector
var previousPageRankVector = mathjs.zeros(numTags);
// initialize the difference between the current PageRank vector and the previous PageRank vector
var difference = mathjs.subtract(PageRankVector, previousPageRankVector);

// initialize the number of iterations
fork icon0
star icon0
watch icon0

84
85
86
87
88
89
90
91
92
93
var Npnt   = y_dat.length;//length(y_dat);		// number of data points
var p_old  = math.zeros(Npar,1);		// previous set of parameters
var y_old  = math.zeros(Npnt,1);		// previous model, y_old = y_hat(t;p_old)
var X2     = 1e-2/eps;			// a really big initial Chi-sq value
var X2_old = 1e-2/eps;			// a really big initial Chi-sq value
var J = math.zeros(Npnt,Npar);
/*var J      = new Array(Npnt);//zeros(Npnt,Npar);		// Jacobian matrix
for(var  i=0;i<Npnt;i++){
    J[i] = new Array(Npar);
}*/
fork icon0
star icon0
watch icon0

+ 14 other calls in file

22
23
24
25
26
27
28
29
30
  if (s.type === 'Fixed') n += 2;
  else n++;
});

const
  arr = math.zeros(n + 2, n + 2),
  ans = math.zeros(n + 2, 1);

n = 0;
fork icon0
star icon0
watch icon0

+ 5 other calls in file

65
66
67
68
69
70
71
72
73
74
75
76


/* Solve */
function solve1(data) {
    data = parseData(data);
    let max_dim = data.reduce((acc, pos) => math.max(...pos, acc), 0);
    let cubes = math.zeros(max_dim, max_dim, max_dim);


    let sa_total = 0;
    data.forEach(pos => {
        
fork icon0
star icon0
watch icon0

+ 5 other calls in file

56
57
58
59
60
61
62
63
64

var counter = 0;

while( (math.larger(y[high], math.add(y[low], epsilon)) && counter < maximumIterations) || counter < minimumIterations ) {

    var S = math.zeros(1, size);
    for(var i = 0; i < size + 1; ++i) {
        S = math.add(S, math.subset(vertices, math.index(i, [0, size])));
    }
fork icon0
star icon0
watch icon0

+ 9 other calls in file

25
26
27
28
29
30
31
32
33
34
  history: {
    input: [],
    output: [],
  },
  subscribers: [],
  hidden: M.zeros(dim.hidden),
  bias: M.random([dim.hidden], -1, 1),
  transforms: {},
};
this.log('CREATED', this.options);
fork icon0
star icon0
watch icon2

31
32
33
34
35
36
37
38
39
40
}

function makePairingMatrix(data) {
    var map = makeTeamMapping(a);
    var n = map.length;
    var Mat = math.zeros(n, n, 'sparse');

    for (i = 0; i < data.length; ++i) {
        var r1 = data[i][0];
        var r2 = data[i][1];
fork icon0
star icon0
watch icon3

+ 3 other calls in file