Java code Implementation----notes on matrix computing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.