Apply weight to vector. - Java java.lang

Java examples for java.lang:Math Matrix

Description

Apply weight to vector.

Demo Code


//package com.java2s;

public class Main {
    /**//from   ww w . j  a  v a  2 s . co m
     * Apply weight to vector.
     * 
     * If the weight vector is longer than s, only the first elements are used.
     * If the weight vector is shorter than s, the last elements of s are not
     * weighted.
     * 
     * @param data
     *            Vector to apply the weight.
     * @param weight
     *            Weighting coefficients.
     */
    public static void weight(double[] data, double[] weight) {
        for (int j = 0; j < Math.min(data.length, weight.length); j++)
            data[j] *= weight[j];
    }
}

Related Tutorials