Java Array Subtract subtractArray(double[] array1, double[] array2)

Here you can find the source of subtractArray(double[] array1, double[] array2)

Description

subtract Array

License

Open Source License

Declaration

public static double[] subtractArray(double[] array1, double[] array2) 

Method Source Code

//package com.java2s;
/**/*from w  w w. ja  v a  2 s  . co  m*/
* Copyright (c) Acroquest Technology Co, Ltd. All Rights Reserved.
* Please read the associated COPYRIGHTS file for more details.
*
* THE SOFTWARE IS PROVIDED BY Acroquest Technolog Co., Ltd.,
* WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDER BE LIABLE FOR ANY
* CLAIM, DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/

public class Main {

    public static double[] subtractArray(double[] array1, double[] array2) {
        if (array1.length != array2.length) {
            throw new IllegalArgumentException("The dimensions have to be equal!");
        }

        double[] result = new double[array1.length];
        assert array1.length == array2.length;
        for (int i = 0; i < array1.length; i++) {
            result[i] = array1[i] - array2[i];
        }

        return result;
    }
}

Related

  1. subtract(float[] dividend, float[] divisor)
  2. subtract(int a, int[] b)
  3. subtract(int bytesPerDim, int dim, byte[] a, byte[] b, byte[] result)
  4. subtract(int[] a, int[] b)
  5. subtract2(double[] v1, double[] v2, double[] res)
  6. subtractArray(float[] arr1, float[] arr2)
  7. subtractElementwise(int[] a, int[] b)
  8. subtractImages(float[][] top, float[][] base)
  9. subtractInPlace(double[] a, double[] b)