gpt4 book ai didi

hadoop - 如何使用 TwoDArrayWritable 从映射器发出二维双数组

转载 作者:可可西里 更新时间:2023-11-01 16:16:32 25 4
gpt4 key购买 nike

我想使用 TwoDArrayWritable 作为值发出一个二维 double 组。

如何编写 context.write(key , )

编辑

并且在 Reducer 中如何在二维 double 组中获取它们并打印值。

我在 MapperWrote

row = E.length;
col = E[0].length;
TwoDArrayWritable array = new TwoDArrayWritable (DoubleWritable.class);
DoubleWritable[][] myInnerArray = new DoubleWritable[row][col];
// set values in myInnerArray
for (int k1 = 0; k1 < row; k1++) {
for(int j1=0;j1< col;j1++){
myInnerArray[k1][j1] = new DoubleWritable(E[k1][j1]);

}
array.set(myInnerArray);
context.write(clusterNumber, array);

但显示空指针异常

13/11/01 16:34:07 INFO mapred.LocalJobRunner: Map task executor complete.
13/11/01 16:34:07 WARN mapred.LocalJobRunner: job_local724758890_0001
java.lang.Exception: java.lang.NullPointerException
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:404)
Caused by: java.lang.NullPointerException
at org.apache.hadoop.io.TwoDArrayWritable.write(TwoDArrayWritable.java:91)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableSerializer.serialize(WritableSerialization.java:100)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableSerializer.serialize(WritableSerialization.java:84)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:945)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:601)
at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:85)
at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.write(WrappedMapper.java:106)
at edu.Mapper.map(Mapper.java:277)


Mapper.java:277 : context.write(clusterNumber, array);

最佳答案

 TwoDArrayWritable array = new TwoDArrayWritable (DoubleWritable.class);
DoubleWritable[][] myInnerArray = new DoubleWritable[10][];
// set values in myInnerArray
array.set(myInnerArray);
context.write(key, array);

我认为 NPE 是因为数组的某些元素为空。根据您发布的代码,我想知道 ecol 是否等于 col

关于hadoop - 如何使用 TwoDArrayWritable 从映射器发出二维双数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19721836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com