final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
final DataSet<double[]> a = env.fromElements(new double[]{0.1, 0.3, 0.8});
final DataSet<double[]> b = env.fromElements(new double[]{0.2, 0.4, 0.7});
a.cross(b).map(new MapFunction<Tuple2<double[],double[]>, Double>() {
final EuclideanDistance distance = new EuclideanDistance();
@Override
public Double map(Tuple2<double[], double[]> value) throws Exception {
return distance.compute(value.f0, value.f1);
}
})
.print(); // start execution and output result to STDOUT
1条答案
按热度按时间iugsix8n1#
这应该能奏效
我用过这里
org.apache.commons.math3.ml.distance.EuclideanDistance
计算距离。