Javascript two-dimensional matrix multiplication ., Javascript Multiplication
Baidu and Google could not find the "javascript two-dimensional matrix multiplication", so I will write it for everyone. (I wrote the multiplication of Two Dimensional Matrices of n * n)
The following is the time to paste the Code:
Function matrixMultiplication (a, B) {var len =. length, arr = []; for (var I = 0; I <len; I ++) {arr [I] = []; for (var j = 0; j <len; j ++) {arr [I] [j] = 0; // reset to 0 for (var k = 0; k <len; k ++) {arr [I] [j] + = a [I] [k] * B [k] [j]; // }}} return arr ;}
In addition, we recommend writing the following JavaScript code:
Function matrixMultiplication (a, B) {return. map (function (row) {return row. map (function (_, I) {return row. reduce (function (sum, cell, j) {return sum + cell * B [j] [I] ;}, 0 );});});}
In fact, they all share the same idea.