Java Matrix Flatten flatten2DArray(byte[][] array)

Here you can find the source of flatten2DArray(byte[][] array)

Description

Flattens a uniform 2D array into a 1D array

License

MIT License

Parameter

Parameter Description
array The uniform 2D array to flatten

Return

The flattened 1D array

Declaration

public static byte[] flatten2DArray(byte[][] array) 

Method Source Code

//package com.java2s;
/*/*from w  w w  .  jav a 2  s.  co m*/
 * Copyright (c) 2010 Matthew J. Francis and Contributors of the Bobbin Project
 * This file is distributed under the MIT licence. See the LICENCE file for further information.
 */

public class Main {
    /**
     * Flattens a uniform 2D array into a 1D array
     *
     * @param array The uniform 2D array to flatten
     * @return The flattened 1D array
     */
    public static byte[] flatten2DArray(byte[][] 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;

    }
}

Related

  1. flatten(double[][] matrix)
  2. flatten(double[][] spills)
  3. flatten(int[][] arr)
  4. Flatten(int[][] in, int[] out)
  5. flatten(String[][] table)
  6. flatten2DArray(double[][] array)
  7. flatten4(float[][] in, int size, float[] out)
  8. flattenIndicesCollection(int[][] multipleIndices, int[] extents)
  9. flattenN(float[][] in, int size, int width, float[] out)