/// <summary> /// Multiplies values in two arrays, mutating the first array. /// <para> /// The arrays must be the same length. Each value in {@code array} is multiplied by the value at the /// corresponding index in {@code arrayToMultiplyBy}. /// /// </para> /// </summary> /// <param name="array"> the array to mutate </param> /// <param name="arrayToMultiplyBy"> the array containing values to multiply by </param> public static void mutateByMultiplication(double[] array, double[] arrayToMultiplyBy) { int length = DoubleArrayMath.length(array, arrayToMultiplyBy); for (int i = 0; i < length; i++) { array[i] *= arrayToMultiplyBy[i]; } }
/// <summary> /// Adds values in two arrays together, mutating the first array. /// <para> /// The arrays must be the same length. Each value in {@code arrayToAdd} is added to the value at the /// corresponding index in {@code array}. /// /// </para> /// </summary> /// <param name="array"> the array to mutate </param> /// <param name="arrayToAdd"> the array containing values to add </param> public static void mutateByAddition(double[] array, double[] arrayToAdd) { int length = DoubleArrayMath.length(array, arrayToAdd); for (int i = 0; i < length; i++) { array[i] += arrayToAdd[i]; } }
/// <summary> /// Combines two arrays, returning an array where each element is the combination of the two matching inputs. /// <para> /// Each element in the result will be the combination of the matching index in the two /// input arrays using the operator. The two input arrays must have the same length. /// </para> /// <para> /// The result is always a new array. The input arrays are not mutated. /// /// </para> /// </summary> /// <param name="array1"> the first array </param> /// <param name="array2"> the second array </param> /// <param name="operator"> the operator to use when combining values </param> /// <returns> an array combining the two input arrays using the operator </returns> public static double[] combine(double[] array1, double[] array2, System.Func <double, double, double> @operator) { int length = DoubleArrayMath.length(array1, array2); double[] result = new double[length]; for (int i = 0; i < length; i++) { result[i] = @operator(array1[i], array2[i]); } return(result); }