Recently learning Hadoop, many algorithms need to use matrix computing, such as: collaborative filtering, PageRank, etc.
So practice a bit,
PUBLIC&NBSP;&NBSP;STATIC&NBSP;VOID&NBSP;M1 () {// according to the rules of matrix multiplication, a[4 *3] * b[3,2],// will get a new matrix of r [4 *2] // r[i][j] = a[i][0] * b[0] [j] + // a[i][1] * b[1][j] +// a[i][2] * b[ 2][j]int[][] a = new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 },{ 1, 2, 3} };int [][] b = new int[][]{{1,2},{3,4},{5,6} } ;int [][] r = new int[4][2];int tmp =0;// the number of columns, The result set represents how many times the a matrix needs to be traversed for ( int k =0; k < r[0].length; k++) {// double loop, traverse a matrix for (int i = 0; i< a.length; i++ ) {tmp = 0;// The result of each row, corresponding to an element in the result set for (int j = 0; j < a[0].length; j++) {tmp += a[i][j] * b[j][k] ;} R[i][k]=tmp;}} for (int i = 0; i < r.length; i++) {for (int j = 0; j < r[0].length; j++) {system.out.print (r[i][j] + "\ t");} System.out.println ();}}
This article from "Wandering Footsteps" blog, declined reprint!
Java code Implementation----notes on matrix computing