Package org.jamdev.jpamutils
Class JamArr
java.lang.Object
org.jamdev.jpamutils.JamArr
public class JamArr extends Object
-
Constructor Summary
Constructors Constructor Description JamArr() -
Method Summary
Modifier and Type Method Description static double[][]add(double[][] img, double b)Add a number to a 2D array.static double[]add(double[] a, double b)Subtract a number from an array.static double[]add(double[] a, double[] b)Add two arrays togetherstatic int[]add(int[] a, int b)Subtract a number from an array.static int[]add(int[] a, int[] b)Add two arrays togetherstatic Stringarray2String(double[] array, int decimalPlaces)Convert an array to a comma delimited string.static Stringarray2String(double[] array, int decimalPlaces, String delimiter)Convert an array to a delimited string.static Stringarray2String(float[] array, int decimalPlaces, String delimiter)Convert an array to a delimited string.static Stringarray2String(Number[] array, int decimalPlaces, String delimiter)Convert an array to a delimited string.static booleancontains(int[] arr, int num)Check whether an array contains a number.static double[][]divide(double[][] array, double divisor)Divide each element in a 2D array by a numberstatic double[]divide(double[] array, double divisor)Divide each element in an array by a number.static double[][]divide(double divisor, double[][] array)Divide each element in a 2D array by a numberstatic double[][]exp(double[][] img)Take the exponential of every element in a 2D arraystatic booleanisATrue(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 doublemax(double[] arr)Calculate the maximum value in an arraystatic doublemax(double[][] arr)Calculate the maximum double value of a 2D double array.static doublemax(float[] arr)Calculate the maximum value in an arraystatic intmax(int[] arr)Calculate the maximum value in an arraystatic intmax(int[][] arr)Calculate the maximum int value of a 2D int array.static doublemean(double[] data)Calculate the mean for a double[] arraystatic doublemean(double[][] data)Calculate the mean over all elements of a double[][] array.static double[]mean(double[][] data, int dim)Calculate the mean of all rows or columns in a double[][] array.static doublemean(int[] data)Calculate the mean for a int[] arraystatic Doublemean(ArrayList<? extends Number> array, double InitialtoIgnorePercentage)Calculate the mean of an array of double values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic doublemean(ArrayList<double[]> array, double InitialtoIgnorePercentage, int dim)Calculate the mean of one dimension within a list of points.static doublemeanf(ArrayList<Float> array, double initialtoIgnorePercentage)Calculate the mean of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic doublemedian(double[] numArray)Calculate the median value of an arraystatic doublemedian(double[][] data)Calculate the median of a double[][] array.static double[]median(double[][] data, int dim)Calculate the median of all rows or columns in a double[][] array.static doublemedian(ArrayList<? extends Number> array)Find the median of an ArrayList of doublesstatic doublemedian(ArrayList<? extends Number> array, double ignorePercentage)Find the median of an ArrayList of doublesstatic doublemin(double[] arr)Get the minimum value in an arraystatic doublemin(double[][] arr)Calculate the minimum double value of a 2D double array.static intmin(int[] arr)Get the minimum value in an arraystatic intmin(int[][] arr)Calculate the minimum int value of a 2D int 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 int[]minmax(int[][] arr)Calculate the minimum and maximum value of a 2D array.static doubleminmaxdiff(double[] arr)Calculate the difference between the minimum and maximum value of an array.static double[]normalise(double[] arr)Normalise an arraystatic double[]normalise(double[] arr, double scaleFactor)Normalise an arraystatic double[]pow(double[] array, double exp)Square or raise the power all elements in an arraystatic voidprintArray(double[] array)Print an array to the console.static voidprintArray(double[][] array)Print a 2D double arraystatic voidprintArray(int[] array)static voidprintArray(int[][] array)Print a 2D int arraystatic double[][]product(double[][] img, double b)Multiple a 2D array by a number;static double[][]product(double[][] img1, double[][] img2)Multiply two images together,static double[]product(double[] a, double b)Multiply an array by a number.static double[]product(double[] a, double[] b)/** Multiply two arrays togetherstatic double[]product(int[] a, double b)Multiply an array by a number.static int[]product(int[] a, int b)Multiply an array by a number.static int[]product(int[] a, int[] b)Multiply two arrays togetherstatic double[]rearrange(double[] arr, int[] pos)Shuffle an array according to the given order of elementsstatic float[]rearrange(float[] arr, int[] pos)Shuffle an array according to the given order of elementsstatic int[]rearrange(int[] arr, int[] pos)Shuffle an array according to the given order of elementsstatic String[]rearrange(String[] arr, int[] pos)Shuffle a string array according to the given order of elementsstatic 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 doublestd(double[] data)Calculate the standard deviation for a double[] arraystatic doublestd(double[][] data)Calculate the standard deviation of an array, The standard deviaiton is computed for the flattened array.static double[]std(double[][] data, int dim)Calculate the standard deviation of all rows or columns in a double[][] array.static doublestd(ArrayList<? extends Number> array)Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic doublestd(ArrayList<? extends Number> array, double initialtoIgnorePercentage)Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic doublestd(ArrayList<double[]> array, double initialtoIgnorePercentage, int dim)Calculate the standard deviation of an array of doubles, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic doublestdf(ArrayList<Float> array)Calculate the standard deviation of an array of float values, ignoring an 'initialtoIgnorePercentage' percentage of jumpsstatic doublestdf(ArrayList<Float> array, double initialToIgnorePercentage)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[][]subtract(double[][] img, double b)Subtract a number from a 2D array.static double[]subtract(double[] a, double b)Subtract a number from an array.static double[]subtract(double[] a, double[] b)Subtract two array from each other.static int[]subtract(int[] a, int b)Subtract a number from an array.static int[]subtract(int[] a, int[] b)Subtract two array from each other.static doublesum(double[] array)Sum the elements in an arraystatic doublesum(double[][] array2)Sum the elements in a 2D array.static intsum(int[] array)Sum the elements in an arraystatic double[][]transposeMatrix(double[][] m)Transpose a double[][] matrixstatic booleanunique(double[] array)Check whether there are duplicates within an arraystatic doublevarience(double[] data)Calculate the variance for a double[] array
-
Constructor Details
-
JamArr
public JamArr()
-
-
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.
-
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
-
mean
public static double mean(double[][] data)Calculate the mean over all elements of a double[][] array.- Parameters:
data- - 2D array of double- Returns:
- the mean over all elements.
-
mean
public static double[] mean(double[][] data, int dim)Calculate the mean of all rows or columns in a double[][] array.- Parameters:
data- - 2D array of double - must not be a ragged array.dim- - which dimensions to average over. -1 averages across all elements in the array. 0 averages rows and 1 averages columns.- Returns:
- the mean values, a single value or the mean of all rows/columns
-
median
public static double median(double[][] data)Calculate the median of a double[][] array. Flattens the array and then takes the median value of all elements.- Parameters:
data- - 2D array of double;- Returns:
- the median value of all elements in the array,
-
median
public static double[] median(double[][] data, int dim)Calculate the median of all rows or columns in a double[][] array.- Parameters:
data- - 2D array of double - must not be a ragged array.dim- - which dimensions to average over. -1 calculates the median for a flattened version of all elements in the array. 0 calculates the median of rows and 1 calculates the median of columns.- Returns:
- the mean values, a single value or the mean of all rows/columns
-
std
public static double std(double[][] data)Calculate the standard deviation of an array, The standard deviaiton is computed for the flattened array.- Parameters:
data- - the input array.- Returns:
- - the standard deviation.
-
std
public static double[] std(double[][] data, int dim)Calculate the standard deviation of all rows or columns in a double[][] array.- Parameters:
data- - 2D array of double - must not be a ragged array.dim- - which dimensions to average over. -1 calculates the standard deviation for a flattened array. 0 calculates the standard deviation of rows and 1 calculates the standard deviation of columns.- Returns:
- the mean values, a single value or the mean of all rows/columns
-
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
-
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 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(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 int value of a 2D int 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(double[][] arr)Calculate the maximum double value of a 2D double 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 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
-
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.
-
min
public static int min(int[][] arr)Calculate the minimum int value of a 2D int array.- Parameters:
arr- - the array to find the maximum value of.- Returns:
- the minimum and maximum value in the array
-
min
public static double min(double[][] arr)Calculate the minimum double value of a 2D double array.- Parameters:
arr- - the array to find the maximum value of.- Returns:
- the minimum and maximum 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
-
pow
public static double[] pow(double[] array, double exp)Square or raise the power all elements in an array- Parameters:
array- - the array- Returns:
- array with all elements raised to the power of exp.
-
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(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
-
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 there are duplicates.
-
divide
public static double[] divide(double[] array, double divisor)Divide each element in an array by a number.- Parameters:
array- - the array to divide.divisor- - the number to divide by.- Returns:
- an array with all elements divided by divisor.
-
divide
public static double[][] divide(double[][] array, double divisor)Divide each element in a 2D array by a number- Parameters:
array- - the array to divide.divisor- - the number to divide by.- Returns:
- a new array with all elements divided by divisor.
-
divide
public static double[][] divide(double divisor, double[][] array)Divide each element in a 2D array by a number- Parameters:
array- - the array to divide.divisor- - the number to divide by.- Returns:
- a new array with all elements divided by divisor.
-
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.
-
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,
-
subtract
public static double[] subtract(double[] a, double[] b)Subtract two array from each other.- Parameters:
a- - the first array.b- - the second array. Must be the same length as a- Returns:
- elements in a minus elements in b.
-
subtract
public static double[] subtract(double[] a, double b)Subtract a number from an array.- Parameters:
a- - the first array.b- - the number to subtract from all elements in a.- Returns:
- elements in a minus b.
-
subtract
public static double[][] subtract(double[][] img, double b)Subtract a number from a 2D array.- Parameters:
img- - the array.b- - the number to subtract from all elements in a.- Returns:
- elements in img minus b.
-
add
public static double[] add(double[] a, double[] b)Add two arrays together- Parameters:
a- - the first array.b- - the second array. Must be the same length as a- Returns:
- elements in a plus elements in b.
-
add
public static double[] add(double[] a, double b)Subtract a number from an array.- Parameters:
a- - the first array.b- - the number to add to all elements in a.- Returns:
- elements in a plus b.
-
add
public static double[][] add(double[][] img, double b)Add a number to a 2D array.- Parameters:
img- - the array.b- - the number to add to elements.- Returns:
- elements in img plus b.
-
product
public static double[] product(double[] a, double[] b)/** Multiply two arrays together- Parameters:
a- - the first array.b- - the second array. Must be the same length as a- Returns:
- elements in a multiplied by elements in b.
-
product
public static double[] product(double[] a, double b)Multiply an array by a number.- Parameters:
a- - the first array.b- - the number to add to all elements in a.- Returns:
- elements in a multiplied by b.
-
subtract
public static int[] subtract(int[] a, int[] b)Subtract two array from each other.- Parameters:
a- - the first array.b- - the second array. Must be the same length as a- Returns:
- elements in a minus elements in b.
-
subtract
public static int[] subtract(int[] a, int b)Subtract a number from an array.- Parameters:
a- - the first array.b- - the number to subtract from all elements in a.- Returns:
- elements in a minus b.
-
add
public static int[] add(int[] a, int[] b)Add two arrays together- Parameters:
a- - the first array.b- - the second array. Must be the same length as a- Returns:
- elements in a plus elements in b.
-
add
public static int[] add(int[] a, int b)Subtract a number from an array.- Parameters:
a- - the first array.b- - the number to add to all elements in a.- Returns:
- elements in a plus b.
-
product
public static int[] product(int[] a, int[] b)Multiply two arrays together- Parameters:
a- - the first array.b- - the second array. Must be the same length as a- Returns:
- elements in a multiplied by elements in b.
-
product
public static int[] product(int[] a, int b)Multiply an array by a number.- Parameters:
a- - the first array.b- - the number to add to all elements in a.- Returns:
- elements in a multiplied by b.
-
product
public static double[] product(int[] a, double b)Multiply an array by a number.- Parameters:
a- - the first array.b- - the number to add to all elements in a.- Returns:
- elements in a multiplied by b.
-
product
public static double[][] product(double[][] img, double b)Multiple a 2D array by a number;- Parameters:
a- - the array.b- - the number to multiply all elements by.- Returns:
- the array multiplied by b.
-
exp
public static double[][] exp(double[][] img)Take the exponential of every element in a 2D array- Parameters:
img- - the array- Returns:
- a new array with the exponent of every element
-
product
public static double[][] product(double[][] img1, double[][] img2)Multiply two images together,- Parameters:
img1- - the img.img2- - the scaling.- Returns:
- - the product of the two matrices.
-
rearrange
public static int[] rearrange(int[] arr, int[] pos)Shuffle an array according to the given order of elements- Parameters:
arr- - the input array to shufflepos- - the index array.
-
rearrange
public static double[] rearrange(double[] arr, int[] pos)Shuffle an array according to the given order of elements- Parameters:
arr- - the input array to shufflepos- - the index array.
-
rearrange
public static float[] rearrange(float[] arr, int[] pos)Shuffle an array according to the given order of elements- Parameters:
arr- - the input array to shufflepos- - the index array.
-
rearrange
Shuffle a string array according to the given order of elements- Parameters:
arr- - the input array to shufflepos- - the index array.
-