Java Utililty Methods Matrix Flatten

List of utility methods to do Matrix Flatten

Description

The list of methods to do Matrix Flatten are organized into topic(s).

Method

Stringflatten(String[][] table)
flatten
StringBuilder sb = new StringBuilder();
for (int i = 0; i < table.length; i++) {
    if (i > 0)
        sb.append("\n");
    for (int j = 0; j < table[i].length; j++) {
        String s = table[i][j];
        if (s == null)
            s = "";
...
byte[]flatten2DArray(byte[][] array)
Flattens a uniform 2D array into a 1D array
byte[] flattenedArray = new byte[array.length * array[0].length];
for (int i = 0; i < array.length; i++) {
    System.arraycopy(array[i], 0, flattenedArray, i * array[0].length, array[0].length);
return flattenedArray;
double[]flatten2DArray(double[][] array)
flatten D Array
int length = 0;
for (double[] arr : array) {
    length += arr.length;
double[] flattenArray = new double[length];
int count = 0;
for (double[] arr : array) {
    for (int j = 0; j < arr.length; j++) {
...
voidflatten4(float[][] in, int size, float[] out)
Flatten a 2D array with 4 items in the second dimension into a 1D array.
int count = size * 4 - 1;
for (int i = size; --i >= 0;) {
    out[count--] = in[i][3];
    out[count--] = in[i][2];
    out[count--] = in[i][1];
    out[count--] = in[i][0];
int[]flattenIndicesCollection(int[][] multipleIndices, int[] extents)
Given a multiple n-d indices flatten them to a collection of 1d indices
int[] flattened = new int[multipleIndices.length];
for (int i = 0; i < multipleIndices.length; i++) {
    flattened[i] = flattenIndices(multipleIndices[i], extents);
return flattened;
voidflattenN(float[][] in, int size, int width, float[] out)
Flatten a 2D array with n items in the second dimension into a 1D array.
int count = size * width - 1;
for (int i = size; --i >= 0;) {
    for (int j = width; --j >= 0;) {
        out[count--] = in[i][j];