Java Array Divide divideElementwise(int[] a, int[] b)

Here you can find the source of divideElementwise(int[] a, int[] b)

Description

Divides the values in the two arrays of integers element-wise.

License

Open Source License

Parameter

Parameter Description
a Array of integer dividends.
b Array of integer divisors.

Exception

Parameter Description
ArithmeticException Throws exception when the arrays differ inlength.

Return

Result of element-wise division of arrays.

Declaration

public static double[] divideElementwise(int[] a, int[] b) throws ArithmeticException 

Method Source Code

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

public class Main {
    /**/*  w  w w .  j av  a2s.c  o  m*/
     * Divides the values in the two arrays of integers element-wise.
     *
     * @param a Array of integer dividends.
     * @param b Array of integer divisors.
     * @return Result of element-wise division of arrays.
     * @throws ArithmeticException Throws exception when the arrays differ in
     * length.
     */
    public static double[] divideElementwise(int[] a, int[] b) throws ArithmeticException {

        if (a.length != b.length) {
            throw new ArithmeticException();
        } else {
            double[] result = new double[a.length];
            for (int i = 0; i < a.length; i++) {
                result[i] = (double) a[i] / b[i];
            }
            return result;
        }

    }

    /**
     * Divides the values in the two arrays of doubles element-wise.
     *
     * @param a Array of double dividends.
     * @param b Array of double divisors.
     * @return Result of element-wise division of arrays.
     * @throws ArithmeticException Throws exception when the arrays differ in
     * length.
     */
    public static double[] divideElementwise(double[] a, double[] b) throws ArithmeticException {

        if (a.length != b.length) {
            throw new ArithmeticException();
        } else {
            double[] result = new double[a.length];
            for (int i = 0; i < a.length; i++) {
                result[i] = a[i] / b[i];
            }
            return result;
        }

    }

    /**
     * Divides the values in the two arrays of longs element-wise.
     *
     * @param a Array of long dividends.
     * @param b Array of long divisors.
     * @return Result of element-wise division of arrays.
     * @throws ArithmeticException Throws exception when the arrays differ in
     * length.
     */
    public static double[] divideElementwise(long[] a, long[] b) throws ArithmeticException {

        if (a.length != b.length) {
            throw new ArithmeticException();
        } else {
            double[] result = new double[a.length];
            for (int i = 0; i < a.length; i++) {
                result[i] = (double) a[i] / b[i];
            }
            return result;
        }

    }

    /**
     * Divides the values in the two arrays of floats element-wise.
     *
     * @param a Array of float dividends.
     * @param b Array of float divisors.
     * @return Result of element-wise division of arrays.
     * @throws ArithmeticException Throws exception when the arrays differ in
     * length.
     */
    public static float[] divideElementwise(float[] a, float[] b) throws ArithmeticException {

        if (a.length != b.length) {
            throw new ArithmeticException();
        } else {
            float[] result = new float[a.length];
            for (int i = 0; i < a.length; i++) {
                result[i] = a[i] / b[i];
            }
            return result;
        }

    }

    /**
     * Divides the values in the two arrays of bytes element-wise.
     *
     * @param a Array of byte dividends.
     * @param b Array of byte divisors.
     * @return Result of element-wise division of arrays.
     * @throws ArithmeticException Throws exception when the arrays differ in
     * length.
     */
    public static float[] divideElementwise(byte[] a, byte[] b) throws ArithmeticException {

        if (a.length != b.length) {
            throw new ArithmeticException();
        } else {
            float[] result = new float[a.length];
            for (int i = 0; i < a.length; i++) {
                result[i] = (float) a[i] / b[i];
            }
            return result;
        }

    }

    /**
     * Divides the values in the two matrices element-wise.
     *
     * @param a Matrix of double dividends.
     * @param b Matrix of double divisors.
     * @return   Result of element-wise division of the two matrices.
     * @throws ArithmeticException   Throws an exception when the two matrices are
     * not of the same size.
     */
    public static double[][] divideElementwise(double[][] a, double[][] b) throws ArithmeticException {

        if (a.length != b.length || a[0].length != b[0].length) {
            throw new ArithmeticException();
        } else {
            double[][] result = new double[a.length][a[0].length];
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    result[i][j] = a[i][j] / b[i][j];
                }
            }
            return result;
        }

    }

    /**
     * Divides the values in the two matrices element-wise.
     *
     * @param a Matrix of integer dividends.
     * @param b Matrix of integer divisors.
     * @return   Result of element-wise division of the two matrices.
     * @throws ArithmeticException   Throws an exception when the two matrices are
     * not of the same size.
     */
    public static double[][] divideElementwise(int[][] a, int[][] b) throws ArithmeticException {

        if (a.length != b.length || a[0].length != b[0].length) {
            throw new ArithmeticException();
        } else {
            double[][] result = new double[a.length][a[0].length];
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    result[i][j] = (double) a[i][j] / b[i][j];
                }
            }
            return result;
        }

    }

    /**
     * Divides the values in the two matrices element-wise.
     *
     * @param a Matrix of float dividends.
     * @param b Matrix of float divisors.
     * @return   Result of element-wise division of the two matrices.
     * @throws ArithmeticException   Throws an exception when the two matrices are
     * not of the same size.
     */
    public static float[][] divideElementwise(float[][] a, float[][] b) throws ArithmeticException {

        if (a.length != b.length || a[0].length != b[0].length) {
            throw new ArithmeticException();
        } else {
            float[][] result = new float[a.length][a[0].length];
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    result[i][j] = a[i][j] / b[i][j];
                }
            }
            return result;
        }

    }

    /**
     * Divides the values in the two matrices element-wise.
     *
     * @param a Matrix of double dividends.
     * @param b Matrix of double divisors.
     * @return   Result of element-wise division of the two matrices.
     * @throws ArithmeticException   Throws an exception when the two matrices are
     * not of the same size.
     */
    public static double[][] divideElementwise(long[][] a, long[][] b) throws ArithmeticException {

        if (a.length != b.length || a[0].length != b[0].length) {
            throw new ArithmeticException();
        } else {
            double[][] result = new double[a.length][a[0].length];
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    result[i][j] = (double) a[i][j] / b[i][j];
                }
            }
            return result;
        }

    }

    /**
     * Divides the values in the two matrices element-wise.
     *
     * @param a Matrix of float dividends.
     * @param b Matrix of float divisors.
     * @return   Result of element-wise division of the two matrices.
     * @throws ArithmeticException   Throws an exception when the two matrices are
     * not of the same size.
     */
    public static float[][] divideElementwise(byte[][] a, byte[][] b) throws ArithmeticException {

        if (a.length != b.length || a[0].length != b[0].length) {
            throw new ArithmeticException();
        } else {
            float[][] result = new float[a.length][a[0].length];
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    result[i][j] = (float) a[i][j] / b[i][j];
                }
            }
            return result;
        }

    }

    /**
     * Divides the values in the two matrices element-wise.
     *
     * @param a Matrix of double dividends.
     * @param b Matrix of double divisors.
     * @return   Result of element-wise division of the two matrices.
     * @throws ArithmeticException   Throws an exception when the two matrices are
     * not of the same size.
     */
    public static double[][] divideElementwise(double[][] a, int[][] b) throws ArithmeticException {

        if (a.length != b.length || a[0].length != b[0].length) {
            throw new ArithmeticException();
        } else {
            double[][] result = new double[a.length][a[0].length];
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    result[i][j] = a[i][j] / b[i][j];
                }
            }
            return result;
        }

    }
}

Related

  1. divideElements(double[] v1, double[] v2, double[] rs)
  2. divideElements(final int j, final int numRows, final double[] u, final int startU, final double realA, final double imagA)
  3. divideElements(final int j, final int numRows, final float[] u, final float u_0)
  4. divideElements4arg(final int j, final int numRows, final double[] u, final double u_0)
  5. divideElements_Bcol(int j, int numRows, int numCols, double[] u, double b[], int startB, double u_0)
  6. divideImage(float[][] base, float[][] divisor)
  7. divideInPlace(double denominator, double[] target)
  8. divideInPlace(float[] vector, float val)
  9. divideIntoChunks(Object[] objs, int chunkSize)