Package PamUtils
Class PamArrayUtils
java.lang.Object
PamUtils.PamArrayUtils
Some math and utility functions for arrays and Lists.
- Author:
- Jamie Macaulay
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 elementsstatic boolean
arrEquals
(int[] shape, int[] shape2) Check if two int arrays contain the same elementsstatic boolean
arrEquals
(long[] shape, long[] shape2) Check if two long arrays contain the same elementsstatic boolean
Check if two Long arrays contain the same elementsstatic 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 numberstatic 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.static PamDataUnit
getMinTimeMillis
(List<PamDataUnit> dataUnits) 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 falsestatic 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 astatic double
max
(double[] arr) Calculate the maximum value in an arraystatic double
max
(float[] arr) Calculate the maximum value in an arraystatic int
max
(int[] arr) Calculate the maximum value in an arraystatic int
maxPos
(double[] arr) Get the index of the maximum value in an arraystatic int
maxPos
(float[] arr) Get the index of the maximum value in an arraystatic int[]
maxPos
(float[][] arr) Get the index of the maximum value within a 2D matrixstatic double
mean
(double[] data) Calculate the mean for a double[] arraystatic double
mean
(int[] data) Calculate the mean for a int[] arraystatic Double
Calculate the mean of an array of double values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double
Calculate the mean of one dimension within a list of points.static double
Calculate the mean of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double
median
(double[] numArray) Calculate the median value of an arraystatic double
Find the median of an ArrayList of doublesstatic double
Find the median of an ArrayList of doublesstatic double
min
(double[] arr) Get the minimum value in an arraystatic int
min
(int[] arr) Get the minimum value in an arraystatic 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 arraystatic double[]
normalise
(double[] arr) Normalise an arraystatic double[]
normalise
(double[] arr, double scaleFactor) Normalise an arraystatic float[]
normalise
(float[] arr, double scaleFactor) Normalise an arraystatic long[]
object2Primitve
(Long[] arr) 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 arraystatic void
printArray
(float[] array) Print an array to the console.static void
printArray
(int[] array) static void
printArray
(int[][] array) Print a 2D int arraystatic void
printArray
(Long[] array) Print a Long arraystatic void
printArrayRaw
(double[] array) Print an array to the console with no index numbersSorts and array and returns the index of the sorted elements of the array.static <T> ArrayList<T>
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[] arraystatic double[]
std
(double[][] data) Get the standard deviation for a 2D double arraystatic double
Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double
Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double
Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double
Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double
Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic double[]
string2array
(String array) 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 arraystatic double
sum
(double[][] array2) Sum the elements in a 2D array.static int
sum
(int[] array) Sum the elements in an arraystatic double[][]
transposeMatrix
(double[][] m) Transpose a double[][] matrixstatic boolean
unique
(double[] array) Check whether there are duplicates within an arraystatic double
varience
(double[] data) Calculate the variance for a double[] array
-
Constructor Details
-
PamArrayUtils
public PamArrayUtils()
-
-
Method Details
-
mean
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 pointsInitialtoIgnorePercentage
- : ignore the first percentage of resultsdim
- - the dimension of the point to calculate the average for- Returns:
- the mean of one dimension of the list of the points.
-
std
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
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
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
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
Find the median of an ArrayList of doubles- Parameters:
array
- the array to calculate the median forignorePercentage
- the percentage of initial results on the array to ignore- Returns:
- the median of the results whihc are not included in the ignorePercentage
-
median
Find the median of an ArrayList of doubles- Parameters:
array
-- Returns:
- median of the array.
-
getMinTimeMillis
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
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
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
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
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 byarrayToSort
- - 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 normalisescaleFactor
- - 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 normalisescaleFactor
- - 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 splitstart
- - the start indexend
- - 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
Print a Long array- Parameters:
array
- - the array to print.
-
list2ArrayD
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 arraydivisor
- - the number- Returns:
-
array2String
Convert an array to a delimited string.- Parameters:
array
- - the input array to convert to a stringdecimalplaces
- - the number of decimal places to save as characters. More means a longer string.delimitter
- - the delimiter e.g. ",".- Returns:
- the input array.
-
array2String
Convert an array to a delimited string.- Parameters:
array
- - the input array to convert to a stringdecimalplaces
- - the number of decimal places to save as characters. More means a longer string.delimitter
- - the delimiter e.g. ",".- Returns:
- the input array.
-
array2String
Convert an array to a delimited string.- Parameters:
array
- - the input array to convert to a stringdecimalplaces
- - the number of decimal places to save as characters. More means a longer string.delimitter
- - the delimiter e.g. ",".- Returns:
- the input array.
-
string2array
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
Convert an array to a comma delimited string.- Parameters:
array
- - the input array to convert to a stringdecimalplaces
- - the number of decimal places to save as characters. More means a longer string.- Returns:
- the input array.
-
string2array
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
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
Convert primitive long array to Long object array.- Parameters:
arr
- - primitive long array- Returns:
- a Long array
-
primitive2Object
Convert primitive double array to Double object array.- Parameters:
arr
- - primitive double array- Returns:
- a Double array
-
primitive2Object
Convert primitive int array to Integer object array.- Parameters:
arr
- - primitive int array- Returns:
- a Ineteger array
-
object2Primitve
-
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
-