Java Matrix Flatten flatten(double[][] matrix)

Here you can find the source of flatten(double[][] matrix)

Description

flatten

License

Open Source License

Declaration

public static double[] flatten(double[][] matrix) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double[] flatten(double[][] matrix) {
        int matrixHeight = matrix.length;
        int matrixWidth = matrix[0].length;

        double[] flattened = new double[matrixWidth * matrixHeight];
        // Copy over the kernel contents
        for (int i = 0; i < matrixHeight; i++) {
            System.arraycopy(matrix[i], 0, flattened, i * matrixWidth, matrixWidth);
        }//from  ww  w.j a  va 2 s  .  c om
        return flattened;
    }

    public static float[] flatten(float[][] matrix) {
        int matrixHeight = matrix.length;
        int matrixWidth = matrix[0].length;

        float[] flattened = new float[matrixWidth * matrixHeight];
        // Copy over the kernel contents
        for (int i = 0; i < matrixHeight; i++) {
            System.arraycopy(matrix[i], 0, flattened, i * matrixWidth, matrixWidth);
        }
        return flattened;
    }

    public static int[] flatten(int[][] matrix) {
        int matrixHeight = matrix.length;
        int matrixWidth = matrix[0].length;

        int[] flattened = new int[matrixWidth * matrixHeight];
        // Copy over the kernel contents
        for (int i = 0; i < matrixHeight; i++) {
            System.arraycopy(matrix[i], 0, flattened, i * matrixWidth, matrixWidth);
        }
        return flattened;
    }
}

Related

  1. flatten(boolean[][] array)
  2. flatten(byte[][] matrix)
  3. flatten(double[][] arr)
  4. flatten(double[][] array)
  5. flatten(double[][] array)
  6. flatten(double[][] matrix)
  7. flatten(double[][] spills)
  8. flatten(int[][] arr)
  9. Flatten(int[][] in, int[] out)