Here you can find the source of flatten(double[][] matrix)
Parameter | Description |
---|---|
matrix | a matrix of doubles |
public static Double[] flatten(double[][] matrix)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w.j a v a 2 s . co m * Flatten an array. * @param matrix a matrix of doubles * @return the linearized given matrix */ public static Double[] flatten(double[][] matrix) { int linearLength = 0; // Determine the length of the linearized array for (double[] array : matrix) { linearLength += array.length; } Double[] linear = new Double[linearLength]; // array index int i = 0; for (double[] array : matrix) { for (double el : array) { // Assign the element and update the index linear[i] = el; i++; } } return linear; } }