Class ArrayOperations


  • public class ArrayOperations
    extends Object
    General methods for updating arrays
    Author:
    gman6028
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayOperations()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addTo​(double[] destination, double[] addToDestination, int numberOfElements)
      Add the values of a second array element-wise to the first array
      static Object[] addtoStart​(Object elementToPrepend, Object[] theArray)
      add an element to the start of the passed in array.
      static double dotProduct​(double[] d1, double[] d2, int numberOfElements)
      Return the dot product of two arrays The dot product is found by multiplying the elements of each array at each position together and then taking the sum of the multiplied values e.g.
    • Constructor Detail

      • ArrayOperations

        public ArrayOperations()
    • Method Detail

      • addTo

        public static void addTo​(double[] destination,
                                 double[] addToDestination,
                                 int numberOfElements)
        Add the values of a second array element-wise to the first array
        Parameters:
        destination - the array to be updated
        addToDestination - array of values to be added to destination array
        numberOfElements - number of elements in array to be updated
      • dotProduct

        public static double dotProduct​(double[] d1,
                                        double[] d2,
                                        int numberOfElements)
        Return the dot product of two arrays The dot product is found by multiplying the elements of each array at each position together and then taking the sum of the multiplied values e.g. a[1]*b[1]+ a[2]*b[2] + a[3]*b[3] etc
        Parameters:
        d1 - first array in the dot product
        d2 - second array in the dot product
        numberOfElements - number of elements in each array
        Returns:
        the value of the dot product
      • addtoStart

        public static Object[] addtoStart​(Object elementToPrepend,
                                          Object[] theArray)
        add an element to the start of the passed in array. Note that this involves a copy of the original array
        Parameters:
        elementToPrepend - the element to add to start
        theArray - the array to prepend
        Returns:
        the new array