Java Array Value Dot Product arrayMultiplication(double[] a, double[] b)

Here you can find the source of arrayMultiplication(double[] a, double[] b)

Description

Elementwise multiplication of arrays

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Exception

Parameter Description
ArrayStoreException an exception

Return

double array containing a[i] * b[i]

Declaration

public static double[] arrayMultiplication(double[] a, double[] b) throws ArrayStoreException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww w  .  j a  v a 2 s  .  c  o m
     * Elementwise multiplication of arrays
     * 
     * @param a
     * @param b
     * @return double array containing a[i] * b[i]
     * @throws ArrayStoreException
     */
    public static double[] arrayMultiplication(double[] a, double[] b) throws ArrayStoreException {
        if (a == null || b == null) {
            return null;
        }
        if (a.length != b.length) {
            throw new ArrayStoreException("Array sizes do not match.");
        }
        if (a.length == 0) {
            throw new ArrayStoreException("Array of length zero.");
        }

        double[] ret = new double[a.length];

        for (int i = 0; i < ret.length; i++) {
            ret[i] = a[i] * b[i];
        }

        return ret;
    }
}

Related

  1. arrayDot(final Double[] first, final Double[] second)
  2. arrayDot2Zero(String[] values)
  3. arrayMultiply(double[] a, double[] b)
  4. arrayProduct(int[] vs)