Here you can find the source of flatten(double[][] matrix)
public static double[] flatten(double[][] matrix)
//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; } }