Java Array Max Value maxBetween(int[] arr1, int[] arr2)

Here you can find the source of maxBetween(int[] arr1, int[] arr2)

Description

Returns an array of identical shape containing the maximum of the values between each corresponding index.

License

Open Source License

Parameter

Parameter Description
arr1 a parameter
arr2 a parameter

Declaration

public static int[] maxBetween(int[] arr1, int[] arr2) 

Method Source Code

//package com.java2s;
/* ---------------------------------------------------------------------
 * Numenta Platform for Intelligent Computing (NuPIC)
 * Copyright (C) 2014, Numenta, Inc.  Unless you have an agreement
 * with Numenta, Inc., for a separate license for this software code, the
 * following terms and conditions apply:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero Public License for more details.
 *
 * You should have received a copy of the GNU Affero Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 *
 * http://numenta.org/licenses///ww w .  j a v  a 2  s . com
 * ---------------------------------------------------------------------
 */

public class Main {
    /**
     * Returns an array of identical shape containing the maximum
     * of the values between each corresponding index. Input arrays
     * must be the same length.
     *
     * @param arr1
     * @param arr2
     * @return
     */
    public static int[] maxBetween(int[] arr1, int[] arr2) {
        int[] retVal = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            retVal[i] = Math.max(arr1[i], arr2[i]);
        }
        return retVal;
    }

    /**
     * Returns the maximum value in the specified array
     * @param array
     * @return
     */
    public static int max(int[] array) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }

    /**
     * Returns the maximum value in the specified array
     * @param array
     * @return
     */
    public static double max(double[] array) {
        double max = Double.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }
}

Related

  1. maxAbs(double[] a, int begin, int end)
  2. maxAbs(float[] a, int off, int length)
  3. maxarr(double[] a)
  4. maxArray(double[] input)
  5. maxArray(int[] arr)
  6. maxbits(int[] i, int pos, int length)
  7. maxbits32(int[] i, int pos)
  8. maxCommonLeadingWhitespaceForAll(String[] strings)
  9. maxcount(int[] vals, int max, int maxcount)