KSLArrays
This class has some array manipulation methods that I have found useful over the years.
Functions
Performs element-wise absolute value on the array. The array is changed in place.
This operation is in-place.
Adds the two arrays element by element. Arrays must have same length and must not be null.
Element-wise application of the supplied function. The array is changed in place. Using FunctionIfc avoids autoboxing when dealing with primitive doubles.
Returns a BoxPlotSummary that summarizes the passed in array of values
Computes the cartesian product of the two arrays. Returns a list of pairs where the first element of the pair is from the first array and the second element of the pair is from the second array. This produces all possible combinations of the elements as the pairs. If the first array has n elements and the second array has m elements then the number of pairs produced is n x m.
Computes the cartesian product of the two collections. Returns a list of pairs where the first element of the pair is from the first collection and the second element of the pair is from the second collection. This produces all possible combinations of the elements as the pairs. If the first collection has n elements and the second collection has m elements then the number of pairs produced is n x m.
The rows of the sets array are treated like elements in sets. The function returns the element stored at the index of the cartesian product of the sets. The index must be between 0 and (n-1), where n is the number of elements in the cartesian product. The elements start at 0. Since the elements of the arrays represent a set, the values must be unique. That is, no duplicates are permitted within an individual array.
Checks if any element of the array is equal to Double.NaN
Converts the 2-D array to a 1-D array by processing the source src array row-wise and concatenating the rows. For example if the data is organized as follows:
Each labeled array in the map becomes a column in the returned array. Each array in the map must have the same number of elements.
Each labeled array in the map becomes a row in the returned array, which may be ragged because each row in the array may have a different length.
Copies all but element index of array fromA into array toB If fromA has 1 element, toB will be empty
Returns a count of the elements that are of the same type as the target class.
Computes the difference, (di = xi+k - xi) for i = 0 until x.size - k This is the discrete difference operator. For example, if k = 1, then d0 = x1 - x0, d1 = x2 - x1, ..., dx.size - 2 = xx.size -1 - xx.size -2 and returns the new array of differences.
This operation is in-place.
Divides the arrays' element by element. Arrays must have same length and must not be null.
Copies the supplied 2-D array by expanding to the maximum number of columns of the supplied (ragged) array so that the returned array is rectangular, where all row arrays have the same number of elements (columns).
The destination array is mutated by this method
If the array is empty or the element is not found, -1 is returned.
If the array is empty, -1 is returned.
Returns the index associated with the maximum element in the array For ties, this returns the first found.
Returns the index associated with the maximum element in the array For ties, this returns the first found
Returns the index associated with the minimum element in the array For ties, this returns the first found.
Returns the index associated with the minimum element in the array For ties, this returns the first found
Examines each element, a_i starting at 0, and determines if all the elements are equal a_0 != a_1 != a_2, etc.
Examines each element, a_i starting at 0, and determines if all the elements are equal a_0 = a_1 = a_2, etc.
Examines each element, a_i starting at 0, and determines if all the elements are decreasing a_0 gte a_1 gte a_2, etc.
Examines each element, a_i starting at 0, and determines if all the elements are increasing a_0 lte a_1 lte a_2, etc.
The arrays must be rectangular and n columns of first must be same and n rows for second
A 2-D array is rectangular if all rows have the same number of elements (columns).
An array is rectangular if all rows have the same number of elements (columns).
The collection of arrays is considered rectangular if all arrays in the collection have the same number of elements.
Examines each element, a_i starting at 0, and determines if all the elements are strictly decreasing a_0 gt a_1 gt a_2, etc.
Examines each element, a_i starting at 0, and determines if all the elements are strictly increasing a_0 lt a_1 lt a_2, etc.
Examines each element, a_i starting at 0, and determines if any element is less than or equal to 0.0.
Assumes that the array can be ragged. Returns the number of elements in the row array that has the most elements.
Subtracts the arrays element by element. Arrays must have same length and must not be empty. Computes the average of the squares of the differences.
Returns a new array that has been scaled so that the values are between the minimum and maximum values of the supplied array
Assumes that the 2-D array can be ragged. Returns the number of columns necessary that would cause the array to not be ragged. In other words, the minimum number of columns to make the array an un-ragged array (matrix) where all row arrays have the same number of elements.
contributed by Andrew Gibson round a scalar double to a multiple of granularity note that 0 a granularity value is interpreted as "no rounding"
contributed by Andrew Gibson round a 1D array x to a multiple of a scalar granularity value note that 0 or null granularity values are interpreted as "no rounding"
contributed by Andrew Gibson round the 1D array x to a multiple of granularity (double[]) note that 0 or null granularity values are interpreted as "no rounding"
The arrays must be rectangular with the number of rows of the first array equal to the number of columns of the second array.
This operation is in-place.
Multiplies the two arrays element by element. Arrays must have same length.
Returns a new array that has been scaled so that the values are the (x - avg)/sd values of the supplied array
Assumes that the entries in the list are string representations of double values. Each String[] can have a different number of elements. Thus, the returned array may be ragged.
Converts the array of strings to Doubles
Performs element-wise modulo (%) operator on the array. The array is changed in place.
Removes the element at the index. If the index is out of bounds, then a copy of the array is returned.
Returns a new array with duplicate data values removed from the original array, preserving the order of the observations.
Returns a new array in the same order as the original array but with the specified value removed. All instances of the value will be removed.
contributed by Andrew Gibson simple way to create a n-element vector of the same value (x)
contributed by Andrew Gibson calculate the number of decimal places needed to give sf digits
contributed by Andrew Gibson calculate the number of decimal places needed to give AT LEAST sf digits to all values
contributed by Andrew Gibson
Returns a statistic that summarizes the passed in array of values
This operation is in-place.
Subtracts the arrays element by element. Arrays must have same length and must not be null.
Subtracts the arrays element by element. Arrays must have same length and must not be empty. Computes the sum of the squares of the differences.
The array must have non-negative elements and not be empty
The array must not be null.
Converts the list of arrays to an array of arrays.
Converts the two-dimensional array into a list containing the arrays. The rows of the array become the elements of the list.
Convert the 2D array of double to a 2D array of Double with each element the corresponding value
Convert the array of int to an array of double with each element the corresponding value
Convert the array of long to an array of double with each element the corresponding value
Converts any null values to replaceNull. For Array
Converts any null values to replaceNull, for Array
Converts any null values to replaceNull, for Array
Converts any nulls to replaceNull. For List
Converts any nulls to zero, for List
Converts any nulls to replaceNull
Convert the array of doubles to an array of strings with each element the corresponding value
Copies the supplied array by trimming to the minimum number of columns of the supplied (potentially ragged) array so that the returned array is rectangular, where all row arrays have the same number of elements (columns)