List of utility methods to do Matrix Flatten
boolean[] | flatten(boolean[][] array) Takes a two-dimensional array and creates a one dimensional array by placing the second dimension arrays one after another. int n = count(array); boolean[] result = new boolean[n]; int o = 0; for (boolean[] b : array) { System.arraycopy(b, 0, result, o, b.length); o += b.length; return result; ... |
byte[] | flatten(byte[][] matrix) Converts the matrix into a flat array, row after row. byte[] result; int i; int n; int len; len = 0; for (i = 0; i < matrix.length; i++) len += matrix[i].length; result = new byte[len]; ... |
double[] | flatten(double[][] arr) flatten double[] ret = new double[arr.length * arr[0].length]; int count = 0; for (int i = 0; i < arr.length; i++) for (int j = 0; j < arr[i].length; j++) ret[count++] = arr[i][j]; return ret; |
double[] | flatten(double[][] array) flatten for (int i = 1; i < array.length; ++i) { if (array[i].length > array[0].length) { throw new IllegalArgumentException(String.format( "Subarray has too many elements (%d). Must be at most array[0].length (%d).%n", array[i].length, array[0].length)); double[] res = new double[array.length * array[0].length]; ... |
double[] | flatten(double[][] array) flatten int size = 0; for (double[] a : array) { size += a.length; double[] newArray = new double[size]; int i = 0; for (double[] a : array) { for (double d : a) { ... |
Double[] | flatten(double[][] matrix) Flatten an array. int linearLength = 0; for (double[] array : matrix) { linearLength += array.length; Double[] linear = new Double[linearLength]; int i = 0; for (double[] array : matrix) { for (double el : array) { ... |
double[] | flatten(double[][] matrix) flatten int matrixHeight = matrix.length; int matrixWidth = matrix[0].length; double[] flattened = new double[matrixWidth * matrixHeight]; for (int i = 0; i < matrixHeight; i++) { System.arraycopy(matrix[i], 0, flattened, i * matrixWidth, matrixWidth); return flattened; |
double[] | flatten(double[][] spills) flatten double[] flat; if (spills.length > 0) { flat = new double[spills.length * spills[0].length]; for (int i = 0; i < spills.length; i++) { for (int j = 0; j < spills[0].length; j++) { flat[i * spills[0].length + j] = spills[i][j]; } else { flat = new double[] {}; return flat; |
int[] | flatten(int[][] arr) flatten int[] ret = new int[arr.length * arr[0].length]; int count = 0; for (int i = 0; i < arr.length; i++) for (int j = 0; j < arr[i].length; j++) ret[count++] = arr[i][j]; return ret; |
int[] | Flatten(int[][] in, int[] out) Flatten if (out == null || out.length < NElem(in)) out = new int[NElem(in)]; int ind = 0; for (int i = 0, s = in.length; i < s; i++) { System.arraycopy(in[i], 0, out, ind, in[i].length); ind += in[i].length; return out; ... |