Here you can find the source of divide(int[] array1, int[] array2)
Parameter | Description |
---|---|
array1 | Numerator |
array2 | Denominator |
public static double[] divide(int[] array1, int[] array2)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:/*w ww . ja va 2s. c o m*/ * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ import java.util.*; public class Main { /** * Divides two arrays element-to-element. * * @param array1 Numerator * @param array2 Denominator * @return The element-wise division of the input arrays */ public static double[] divide(int[] array1, int[] array2) { double[] out = new double[array1.length]; for (int i = 0; i < out.length; i++) out[i] = (double) array1[i] / array2[i]; return out; } /** * Divides all elements in an array by a scalar. * * @param array Input array * @param value Scalar * @return A new array containing the input elements divided by the scalar */ public static double[] divide(int[] array, double value) { double[] out = new double[array.length]; for (int i = 0; i < out.length; i++) out[i] = array[i] / value; return out; } /** * Divides all elements in a map by a scalar. * * @param <A> Key type * @param map Input map * @param value Scalar * @return A new map containing the input elements divided by the scalar */ public static <A> Map<A, Double> divide(Map<A, Integer> map, double value) { Map<A, Double> out = new LinkedHashMap<A, Double>(); for (Map.Entry<A, Integer> entry : map.entrySet()) { out.put(entry.getKey(), entry.getValue() / value); } return out; } /** * Returns the element-wise quotient of two maps. * * @param <A> Key type * @param map1 Input map 1 * @param map2 Input map 2 * @return A new map with the element-wise quotient */ public static <A> Map<A, Double> divide(Map<A, Integer> map1, Map<A, Integer> map2) { Map<A, Double> out = new LinkedHashMap<A, Double>(); for (Map.Entry<A, Integer> entry : map1.entrySet()) { A key = entry.getKey(); out.put(key, (double) entry.getValue() / map2.get(key)); } return out; } }