Package PamUtils

Class PamArrayUtils

java.lang.Object
PamUtils.PamArrayUtils

public class PamArrayUtils extends Object
Some math and utility functions for arrays and Lists.
Author:
Jamie Macaulay
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    array2String(double[] array, int decimalPlaces)
    Convert an array to a comma delimited string.
    static String
    array2String(double[] array, int decimalPlaces, String delimiter)
    Convert an array to a delimited string.
    static String
    array2String(float[] array, int decimalPlaces, String delimiter)
    Convert an array to a delimited string.
    static String
    array2String(Number[] array, int decimalPlaces, String delimiter)
    Convert an array to a delimited string.
    static boolean
    arrEquals(double[] arr1, double[] arr2)
    Check if two double arrays contain the same elements
    static boolean
    arrEquals(int[] shape, int[] shape2)
    Check if two int arrays contain the same elements
    static boolean
    arrEquals(long[] shape, long[] shape2)
    Check if two long arrays contain the same elements
    static boolean
    arrEquals(Long[] shape, Long[] shape2)
    Check if two Long arrays contain the same elements
    static boolean
    contains(int[] arr, int num)
    Check whether an array contains a number.
    static double[]
    divide(double[] array, double max)
    Divide each element in an array by a number
    static float[]
    double2Float(double[] arrd)
    Convert a float array to a double array.
    static float[][]
    double2Float(double[][] arrd)
    Convert a 2D float array to a 2D double array.
    static double[]
    flip(double[] flipArray)
    Flip a double array so that it is in the reverse order.
    static int[]
    flip(int[] flipArray)
    Flip an int array so that it is in the reverse order.
    static double[]
    float2Double(float[] arrf)
    Convert a float array to a double array.
    static double[][]
    float2Double(float[][] arrf)
    Convert a 2D float array to a 2D double array.
    Get the data unit with the lowest time in millis from a data unit list.
    static boolean
    isAllFalse(boolean[] boolArray)
    Check whether all elements in an array are false
    static boolean
    isATrue(boolean[] boolArray)
    Check whether there is a single true value in a boolean array.
    static double[]
    list2ArrayD(List<Double> listArray)
    Convert a list to a primitive double array.
    static double[][]
    matrix2array(us.hebi.matlab.mat.types.Matrix matrix)
    Convert a matrix to a
    static double
    max(double[] arr)
    Calculate the maximum value in an array
    static double
    max(float[] arr)
    Calculate the maximum value in an array
    static int
    max(int[] arr)
    Calculate the maximum value in an array
    static int
    maxPos(double[] arr)
    Get the index of the maximum value in an array
    static int
    maxPos(float[] arr)
    Get the index of the maximum value in an array
    static int[]
    maxPos(float[][] arr)
    Get the index of the maximum value within a 2D matrix
    static double
    mean(double[] data)
    Calculate the mean for a double[] array
    static double
    mean(int[] data)
    Calculate the mean for a int[] array
    static Double
    mean(ArrayList<? extends Number> array, double InitialtoIgnorePercentage)
    Calculate the mean of an array of double values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double
    mean(ArrayList<float[]> array, double InitialtoIgnorePercentage, int dim)
    Calculate the mean of one dimension within a list of points.
    static double
    meanf(ArrayList<Float> array, double initialtoIgnorePercentage)
    Calculate the mean of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double
    median(double[] numArray)
    Calculate the median value of an array
    static double
    median(ArrayList<? extends Number> array)
    Find the median of an ArrayList of doubles
    static double
    median(ArrayList<? extends Number> array, double ignorePercentage)
    Find the median of an ArrayList of doubles
    static double
    min(double[] arr)
    Get the minimum value in an array
    static int
    min(int[] arr)
    Get the minimum value in an array
    static double[]
    minmax(double[] arr)
    Calculate the minimum and maximum value of an array.
    static double[]
    minmax(double[][] arr)
    Calculate the minimum and maximum value of a 2D array.
    static float[]
    minmax(float[][] arr)
    Calculate the minimum and maximum value of a 2D array.
    static int[]
    minmax(int[][] arr)
    Calculate the minimum and maximum value of a 2D array.
    static double
    minmaxdiff(double[] arr)
    Calculate the difference between the minimum and maximum value of an array.
    static int
    minPos(double[] arr)
    Get the minimum index of an array
    static double[]
    normalise(double[] arr)
    Normalise an array
    static double[]
    normalise(double[] arr, double scaleFactor)
    Normalise an array
    static float[]
    normalise(float[] arr, double scaleFactor)
    Normalise an array
    static long[]
     
    static Double[]
    primitive2Object(double[] arr)
    Convert primitive double array to Double object array.
    static Integer[]
    primitive2Object(int[] arr)
    Convert primitive int array to Integer object array.
    static Long[]
    primitive2Object(long[] arr)
    Convert primitive long array to Long object array.
    static void
    printArray(boolean[] boolArray)
     
    static void
    printArray(double[] array)
    Print an array to the console.
    static void
    printArray(double[][] array)
    Print a 2D double array
    static void
    printArray(float[] array)
    Print an array to the console.
    static void
    printArray(int[] array)
     
    static void
    printArray(int[][] array)
    Print a 2D int array
    static void
    printArray(Long[] array)
    Print a Long array
    static void
    printArrayRaw(double[] array)
    Print an array to the console with no index numbers
    static List<Integer>
    sort(ArrayList<? extends Number> array)
    Sorts and array and returns the index of the sorted elements of the array.
    static <T> ArrayList<T>
    sort(ArrayList<? extends Number> arrayOrdered, ArrayList<T> arrayToSort)
    Sort one array by the ordering of another array.
    static double[][]
    split(double[][] arr, int start, int end)
    Split an array based on start index and end index.
    static double
    std(double[] data)
    Calculate the standard deviation for a double[] array
    static double[]
    std(double[][] data)
    Get the standard deviation for a 2D double array
    static double
    std(ArrayList<? extends Number> array)
    Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double
    std(ArrayList<? extends Number> array, double initialtoIgnorePercentage)
    Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double
    std(ArrayList<float[]> array, double initialtoIgnorePercentage, int dim)
    Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double
    Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double
    stdf(ArrayList<Float> array, double initialToIgnorePercentage)
    Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
    static double[]
    Convert a comma delimited string array to a double array.
    static double[]
    string2array(String array, String delimitter)
    Convert a delimited string array to a double array.
    static double
    sum(double[] array)
    Sum the elements in an array
    static double
    sum(double[][] array2)
    Sum the elements in a 2D array.
    static int
    sum(int[] array)
    Sum the elements in an array
    static double[][]
    transposeMatrix(double[][] m)
    Transpose a double[][] matrix
    static boolean
    unique(double[] array)
    Check whether there are duplicates within an array
    static double
    varience(double[] data)
    Calculate the variance for a double[] array

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PamArrayUtils

      public PamArrayUtils()
  • Method Details

    • mean

      public static double mean(ArrayList<float[]> array, double InitialtoIgnorePercentage, int dim)
      Calculate the mean of one dimension within a list of points. e.g. the points might be a list of [x y z] co-ordinates in which case the dim=0 would return the mean of all x points.
      Parameters:
      array - - a list of points
      InitialtoIgnorePercentage - : ignore the first percentage of results
      dim - - the dimension of the point to calculate the average for
      Returns:
      the mean of one dimension of the list of the points.
    • std

      public static double std(ArrayList<float[]> array, double initialtoIgnorePercentage, int dim)
      Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array -
      initialtoIgnorePercentage - - percentage of initial values to ignore.
      Returns:
      standard deviation of array.
    • mean

      public static Double mean(ArrayList<? extends Number> array, double InitialtoIgnorePercentage)
      Calculate the mean of an array of double values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array - of float values.
      InitialtoIgnorePercentage - - the percentahe of results to ignore.
      Returns:
      mean of the array values
    • std

      public static double std(ArrayList<? extends Number> array, double initialtoIgnorePercentage)
      Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array -
      initialtoIgnorePercentage - - percentage of initial values to ignore.
      Returns:
      standard deviation of array.
    • std

      public static double std(ArrayList<? extends Number> array)
      Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array - of float values.
      Returns:
      standard deviation of the array values.
    • median

      public static double median(ArrayList<? extends Number> array, double ignorePercentage)
      Find the median of an ArrayList of doubles
      Parameters:
      array - the array to calculate the median for
      ignorePercentage - the percentage of initial results on the array to ignore
      Returns:
      the median of the results whihc are not included in the ignorePercentage
    • median

      public static double median(ArrayList<? extends Number> array)
      Find the median of an ArrayList of doubles
      Parameters:
      array -
      Returns:
      median of the array.
    • getMinTimeMillis

      public static PamDataUnit getMinTimeMillis(List<PamDataUnit> dataUnits)
      Get the data unit with the lowest time in millis from a data unit list.
      Parameters:
      dataUnits - - a data unit list.
      Returns:
      the data unit with the lowest time in millis.
    • median

      public static double median(double[] numArray)
      Calculate the median value of an array
      Parameters:
      numArray - - the number array
      Returns:
      the median value.
    • meanf

      public static double meanf(ArrayList<Float> array, double initialtoIgnorePercentage)
      Calculate the mean of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array - of float values.
      InitialtoIgnorePercentage - .
      Returns:
      mean of the array values.
    • stdf

      public static double stdf(ArrayList<Float> array)
      Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array - of float values.
      Returns:
      standard deviation of the array values.
    • stdf

      public static double stdf(ArrayList<Float> array, double initialToIgnorePercentage)
      Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumps
      Parameters:
      array - of float values.
      initialtoIgnorePercentage - - percentage of initial values to ignore.
      Returns:
      standard deviation of the array values.
    • mean

      public static double mean(double[] data)
      Calculate the mean for a double[] array
      Parameters:
      data - array of doubles
      Returns:
      the mean of the array
    • mean

      public static double mean(int[] data)
      Calculate the mean for a int[] array
      Parameters:
      data - array of integers
      Returns:
      the mean of the array
    • varience

      public static double varience(double[] data)
      Calculate the variance for a double[] array
      Parameters:
      data - array of doubles
      Returns:
      the variance
    • std

      public static double std(double[] data)
      Calculate the standard deviation for a double[] array
      Parameters:
      data - array of doubles
      Returns:
      the standard deviation
    • std

      public static double[] std(double[][] data)
      Get the standard deviation for a 2D double array
      Parameters:
      data - - a 2D array of doubles
      Returns:
      std for each COLUMN
    • transposeMatrix

      public static double[][] transposeMatrix(double[][] m)
      Transpose a double[][] matrix
      Parameters:
      m - - the matrix transdpose
      Returns:
      the transposed matrix
    • sort

      public static List<Integer> sort(ArrayList<? extends Number> array)
      Sorts and array and returns the index of the sorted elements of the array. Handles duplicate values.
      Parameters:
      array - - the array to sort
      Returns:
      an integer array showing the index of sorted elements from the original input array
    • sort

      public static <T> ArrayList<T> sort(ArrayList<? extends Number> arrayOrdered, ArrayList<T> arrayToSort)
      Sort one array by the ordering of another array. This is a convenience function which sorts one array and then uses the index of that sort to sort another array. The returned array is the sorted arrayToSort. Useful if sorting one ArrayList by another ArrayList
      Parameters:
      arrayOrdered - - the array to sort by
      arrayToSort - - the array to sort. Must be same size as arrayOrdered.
      Returns:
      the arrayToSort with elements sorted by the arrayOrdered.
    • minmaxdiff

      public static double minmaxdiff(double[] arr)
      Calculate the difference between the minimum and maximum value of an array.
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the maximum value in the array
    • minmax

      public static double[] minmax(double[] arr)
      Calculate the minimum and maximum value of an array.
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the minimum and maximum value in the array
    • minmax

      public static float[] minmax(float[][] arr)
      Calculate the minimum and maximum value of a 2D array.
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the minimum and maximum value in the array
    • minmax

      public static double[] minmax(double[][] arr)
      Calculate the minimum and maximum value of a 2D array.
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the minimum and maximum value in the array
    • minmax

      public static int[] minmax(int[][] arr)
      Calculate the minimum and maximum value of a 2D array.
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the minimum and maximum value in the array
    • max

      public static double max(float[] arr)
      Calculate the maximum value in an array
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the maximum value in the array
    • max

      public static double max(double[] arr)
      Calculate the maximum value in an array
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the maximum value in the array
    • max

      public static int max(int[] arr)
      Calculate the maximum value in an array
      Parameters:
      arr - - the array to find the maximum value of.
      Returns:
      the maximum value in the array
    • maxPos

      public static int maxPos(double[] arr)
      Get the index of the maximum value in an array
      Parameters:
      arr - - the array to find the position of the maximum value. m value of.
      Returns:
      the index of the maximum value
    • maxPos

      public static int maxPos(float[] arr)
      Get the index of the maximum value in an array
      Parameters:
      arr - - the array to find the position of the maximum value. m value of.
      Returns:
      the index of the maximum value
    • maxPos

      public static int[] maxPos(float[][] arr)
      Get the index of the maximum value within a 2D matrix
      Parameters:
      arr - - the array to find the position of the maximum value. m value of.
      Returns:
      the index i and j of the maximum value
    • minPos

      public static int minPos(double[] arr)
      Get the minimum index of an array
      Parameters:
      arr - - the array to find the position of the maximum value. m value of.
      Returns:
      the index of the minimum value
    • min

      public static double min(double[] arr)
      Get the minimum value in an array
      Parameters:
      arr - - the array to find the minimu m value of.
      Returns:
      the minimum value in the array.
    • min

      public static int min(int[] arr)
      Get the minimum value in an array
      Parameters:
      arr - - the array to find the minimum value of.
      Returns:
      the minimum value in the array.
    • normalise

      public static double[] normalise(double[] arr)
      Normalise an array
      Parameters:
      arr - - the array to normalise
      Returns:
      normalised copy of the array
    • normalise

      public static double[] normalise(double[] arr, double scaleFactor)
      Normalise an array
      Parameters:
      arr - - the array to normalise
      scaleFactor - - multiply the resulting array by a scale factor.
      Returns:
      normalised copy of the array
    • normalise

      public static float[] normalise(float[] arr, double scaleFactor)
      Normalise an array
      Parameters:
      arr - - the array to normalise
      scaleFactor - - multiply the resulting array by a scale factor.
      Returns:
      normalised copy of the array
    • flip

      public static double[] flip(double[] flipArray)
      Flip a double array so that it is in the reverse order. Note the array is cloned.
      Parameters:
      flipArray - - the waveform to flip
      Returns:
      the array with elements reversed.
    • flip

      public static int[] flip(int[] flipArray)
      Flip an int array so that it is in the reverse order. Note the array is cloned.
      Parameters:
      flipArray - - the waveform to flip
      Returns:
      the array with elements reversed.
    • split

      public static double[][] split(double[][] arr, int start, int end)
      Split an array based on start index and end index. A new array with index 0 as start and the last index at end is created and data from the input array copied to it.
      Parameters:
      arr - - the array to split
      start - - the start index
      end - - the end index
      Returns:
      the split array.
    • sum

      public static int sum(int[] array)
      Sum the elements in an array
      Parameters:
      array - - the array to sum.
      Returns:
      the summation of all the elements in the array.
    • sum

      public static double sum(double[] array)
      Sum the elements in an array
      Parameters:
      array - - the array to sum.
      Returns:
      the summation of all the elements in the array.
    • sum

      public static double sum(double[][] array2)
      Sum the elements in a 2D array.
      Parameters:
      array2 - - the array to sum.
      Returns:
      the summation of all the elements in the array.
    • printArray

      public static void printArray(double[] array)
      Print an array to the console.
      Parameters:
      array - to print
    • printArray

      public static void printArray(float[] array)
      Print an array to the console.
      Parameters:
      array - to print
    • printArrayRaw

      public static void printArrayRaw(double[] array)
      Print an array to the console with no index numbers
      Parameters:
      array - to print
    • printArray

      public static void printArray(int[] array)
    • printArray

      public static void printArray(double[][] array)
      Print a 2D double array
      Parameters:
      array - - the array
    • printArray

      public static void printArray(int[][] array)
      Print a 2D int array
      Parameters:
      array - - the array
    • printArray

      public static void printArray(boolean[] boolArray)
    • printArray

      public static void printArray(Long[] array)
      Print a Long array
      Parameters:
      array - - the array to print.
    • list2ArrayD

      public static double[] list2ArrayD(List<Double> listArray)
      Convert a list to a primitive double array.
      Parameters:
      listArray - - the list.
      Returns:
      the primitive double.
    • unique

      public static boolean unique(double[] array)
      Check whether there are duplicates within an array
      Parameters:
      the - array.
      Returns:
      true if the array is unique
    • divide

      public static double[] divide(double[] array, double max)
      Divide each element in an array by a number
      Parameters:
      array - - the array
      divisor - - the number
      Returns:
    • array2String

      public static String array2String(float[] array, int decimalPlaces, String delimiter)
      Convert an array to a delimited string.
      Parameters:
      array - - the input array to convert to a string
      decimalplaces - - the number of decimal places to save as characters. More means a longer string.
      delimitter - - the delimiter e.g. ",".
      Returns:
      the input array.
    • array2String

      public static String array2String(double[] array, int decimalPlaces, String delimiter)
      Convert an array to a delimited string.
      Parameters:
      array - - the input array to convert to a string
      decimalplaces - - the number of decimal places to save as characters. More means a longer string.
      delimitter - - the delimiter e.g. ",".
      Returns:
      the input array.
    • array2String

      public static String array2String(Number[] array, int decimalPlaces, String delimiter)
      Convert an array to a delimited string.
      Parameters:
      array - - the input array to convert to a string
      decimalplaces - - the number of decimal places to save as characters. More means a longer string.
      delimitter - - the delimiter e.g. ",".
      Returns:
      the input array.
    • string2array

      public static double[] string2array(String array, String delimitter)
      Convert a delimited string array to a double array.
      Parameters:
      array - - the input string containing the number array.
      delimitter - - the delimiter e.g. ",".
      Returns:
      the input array.
    • array2String

      public static String array2String(double[] array, int decimalPlaces)
      Convert an array to a comma delimited string.
      Parameters:
      array - - the input array to convert to a string
      decimalplaces - - the number of decimal places to save as characters. More means a longer string.
      Returns:
      the input array.
    • string2array

      public static double[] string2array(String array)
      Convert a comma delimited string array to a double array.
      Parameters:
      array - - the input string containing the number array.
      Returns:
      the input array.
    • isATrue

      public static boolean isATrue(boolean[] boolArray)
      Check whether there is a single true value in a boolean array.
      Parameters:
      boolArray - - any array of booleans.
      Returns:
      true if there is at least one true in the array.
    • isAllFalse

      public static boolean isAllFalse(boolean[] boolArray)
      Check whether all elements in an array are false
      Parameters:
      boolArray - - any array of booleans.
      Returns:
      true if all elements are false.
    • contains

      public static boolean contains(int[] arr, int num)
      Check whether an array contains a number.
      Parameters:
      arr - - the array.
      num - - the number to check.
      Returns:
      true if the number is contained within the array,
    • float2Double

      public static double[] float2Double(float[] arrf)
      Convert a float array to a double array.
      Parameters:
      arrf - - the float array
      Returns:
      a double array containing the same numbers as arrf.
    • float2Double

      public static double[][] float2Double(float[][] arrf)
      Convert a 2D float array to a 2D double array.
      Parameters:
      arrf - - the float array
      Returns:
      a double array containing the same numbers as arrf.
    • double2Float

      public static float[] double2Float(double[] arrd)
      Convert a float array to a double array.
      Parameters:
      arrd - - the double array
      Returns:
      a double array containing the same numbers as arrf.
    • double2Float

      public static float[][] double2Float(double[][] arrd)
      Convert a 2D float array to a 2D double array.
      Parameters:
      arrd - - the double array
      Returns:
      a double array containing the same numbers as arrf.
    • arrEquals

      public static boolean arrEquals(Long[] shape, Long[] shape2)
      Check if two Long arrays contain the same elements
      Parameters:
      shape - - the array to compare to.
      shape2 - - the array to be compared.
    • arrEquals

      public static boolean arrEquals(int[] shape, int[] shape2)
      Check if two int arrays contain the same elements
      Parameters:
      shape - - the array to compare to.
      shape2 - - the array to be compared.
    • arrEquals

      public static boolean arrEquals(long[] shape, long[] shape2)
      Check if two long arrays contain the same elements
      Parameters:
      shape - - the array to compare to.
      shape2 - - the array to be compared.
    • arrEquals

      public static boolean arrEquals(double[] arr1, double[] arr2)
      Check if two double arrays contain the same elements
      Parameters:
      arr1 - - the array to compare to.
      arr2 - - the array to be compared.
    • primitive2Object

      public static Long[] primitive2Object(long[] arr)
      Convert primitive long array to Long object array.
      Parameters:
      arr - - primitive long array
      Returns:
      a Long array
    • primitive2Object

      public static Double[] primitive2Object(double[] arr)
      Convert primitive double array to Double object array.
      Parameters:
      arr - - primitive double array
      Returns:
      a Double array
    • primitive2Object

      public static Integer[] primitive2Object(int[] arr)
      Convert primitive int array to Integer object array.
      Parameters:
      arr - - primitive int array
      Returns:
      a Ineteger array
    • object2Primitve

      public static long[] object2Primitve(Long[] arr)
    • matrix2array

      public static double[][] matrix2array(us.hebi.matlab.mat.types.Matrix matrix)
      Convert a matrix to a
      Parameters:
      matrix - - the MAT file matrix
      Returns:
      double[][] array of results