Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question: Largest Hub for Question Solutions and Expert Answers

Querify Question: Largest Hub for Question Solutions and Expert Answers Logo Querify Question: Largest Hub for Question Solutions and Expert Answers Logo

Querify Question: Largest Hub for Question Solutions and Expert Answers Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 954918

Querify Question: Largest Hub for Question Solutions and Expert Answers Latest Articles

admin
  • 160
adminEnlightened
Asked: July 21, 20242024-07-21T04:02:03+00:00 2024-07-21T04:02:03+00:00

calculating sum matrix with in reducer

  • 160

I have a custom class MW. MW gets 2 matrices-(ke matrix and val matrix).

And I am trying to sumup all the matrices coming into reducer.

So I need to first parse my string and I stored them into 2 double array. I am geting all the ke matrix and val matrix in reducer.

But I am not able to sumup.

Any suggestion.

Inorder to get the sum outside the forloop,i declared them as static.

public class Reducer  extends Reducer<IntWritable, MW, Text, Text> {       static double[][] key;     static double[][] value;     public void reduce(IntWritable  keys,             Iterable<MW> values, Context context)             throws IOException, InterruptedException {      for (MW c : values)     {         String data = c.toString();         data = data.trim();         String[] parts = data.split("#");             String part1 = parts[0];             String part2 = parts[1];         /*          * Parse key          */         String[] keyrows = part1.split(",");          String[][] keymatrix = new String[keyrows.length][];          int keyr = 0;         for (String keyrow : keyrows) {             keymatrix[keyr++] = keyrow.split("\|");         }          double[][] ke = new double[keymatrix.length][keymatrix[0].length];        for (int i = 0; i<keymatrix.length; i++) {            for (int j = 0; j<keymatrix[0].length; j++) {                ke[i][j] = Double.valueOf(keymatrix[i][j]);         }        }       key = new double[ke.length][ke[0].length];         for(int sumi = 0;sumi<ke.length;sumi++){            for(int sumj=0;sumj<ke[0].length;sumj++){                key[sumi][sumj] += ke[sumi][sumj];            }        }     /*Parsing  value     */           String[] valuerows = part2.split(",");          String[][] valuematrix = new String[valuerows.length][];          int valr = 0;         for (String valuerow : valuerows) {             valuematrix[valr++] = valuerow.split("\|");         }          double[][] val = new double[valuematrix.length][valuematrix[0].length];        for (int i = 0; i<valuematrix.length; i++) {            for (int j = 0; j<valuematrix[0].length; j++) {        val[i][j] = Double.valueOf(valuematrix[i][j]);         }         }           //calculating sum for value         value = new double[val.length][val[0].length];         for(int sumi = 0;sumi<val.length;sumi++){            for(int sumj=0;sumj<val[0].length;sumj++){                value[sumi][sumj] += val[sumi][sumj];            }        }                    }   System.out.println("sum 1");         for(int diai=0;diai<key.length;diai++){             for(int diaj=0;diaj<key[0].length;diaj++){                 System.out.print(key[diai][diaj]+"	");              }             System.out.println("");          }     System.out.println("sum 2");         for(int diai=0;diai<value.length;diai++){             for(int diaj=0;diaj<value[0].length;diaj++){                 System.out.print(value[diai][diaj]+"	");              }             System.out.println("");          } 

UPDATE I think the problem is with in line

 key = new double[ke.length][ke[0].length]; 

and

value = new double[val.length][val[0].length]; 

before summing I am rebuilding the matrix key and value inside the loop.

It should build it once before the loop and then add to it. But to do that I should do

double[][] key = new double[ke.length][ke[0].length]; double[][] value = new double[val.length][val[0].length]; 

before

for (MW c : values)     { 

but How will I get the dimensions outside the for loop?

Related Posts
  • Related Link: how to use second occurrence of a data to update the first occurrence in database reading the raw data from text file c
hadoopmapreduce
  • 0 0 Answers
  • 1k Views
  • 0 Followers
  • 1k
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 1mil
  • Answer 1
  • Best Answers 0
  • Users 40k
  • Popular
  • Answers
  • admin

    vba code excel range not pasting to outlook properly

    • 1 Answer
  • MilaBrext

    Заказать Хавал - только у нас вы найдете цены ниже ...

    • 0 Answers
  • admin

    Creating a Regex to Match the First N Characters of ...

    • 0 Answers
  • Reda
    Reda added an answer Convert Range to Text February 27, 2025 at 8:30 pm

Top Members

admin

admin

  • 1mil Questions
  • 855 Points
Enlightened
Reda

Reda

  • 0 Questions
  • 22 Points
Begginer
Aria Carter

Aria Carter

  • 0 Questions
  • 21 Points
Begginer

Trending Tags

android azuredevops azurepipelines c database debugging decimal docker html ios java javascript jquery php python reactjs regex rubyonrails sql vlc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question: Largest Hub for Question Solutions and Expert Answers

Querify Question: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.