Here you can find the source of matrixToArray(int[][] input, int fromRow, int rows, int fromColumn, int columns)
Parameter | Description |
---|---|
input | a parameter |
fromRow | a parameter |
rows | a parameter |
fromColumn | a parameter |
colums | a parameter |
public static int[] matrixToArray(int[][] input, int fromRow, int rows, int fromColumn, int columns)
//package com.java2s; /*//from ww w .ja v a 2s . c o m * Java Information Dynamics Toolkit (JIDT) * Copyright (C) 2012, Joseph T. Lizier * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts a 2 dimensional array into a single dimension. * Places each column on top of each other. * Provides controllers for selecting a subset of rows or columns. * * @param input * @param fromRow * @param rows * @param fromColumn * @param colums * @return Single dimensional array containing the required data */ public static int[] matrixToArray(int[][] input, int fromRow, int rows, int fromColumn, int columns) { int[] output = new int[rows * columns]; for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { output[c * rows + r] = input[r + fromRow][c + fromColumn]; } } return output; } /** * Converts a 2 dimensional array into a single dimension. * Places each column on top of each other. * Provides controllers for selecting a subset of rows only. * * @param input * @param fromRow * @param rows * @return Single dimensional array containing the required data */ public static int[] matrixToArray(int[][] input, int fromRow, int rows) { return matrixToArray(input, fromRow, rows, 0, input[0].length); } /** * Converts a 2 dimensional array into a single dimension. * Places each column on top of each other. * * @param input * @return Single dimensional array containing the required data */ public static int[] matrixToArray(int[][] input) { return matrixToArray(input, 0, input.length, 0, input[0].length); } /** * Converts a 2 dimensional array into a single dimension. * Places each column on top of each other. * Provides controllers for selecting a subset of rows or columns. * * @param input * @param fromRow * @param rows * @param fromColumn * @param colums * @return Single dimensional array containing the required data */ public static double[] matrixToArray(double[][] input, int fromRow, int rows, int fromColumn, int columns) { double[] output = new double[rows * columns]; for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { output[c * rows + r] = input[r + fromRow][c + fromColumn]; } } return output; } /** * Converts a 2 dimensional array into a single dimension. * Places each column on top of each other. * Provides controllers for selecting a subset of rows only. * * @param input * @param fromRow * @param rows * @return Single dimensional array containing the required data */ public static double[] matrixToArray(double[][] input, int fromRow, int rows) { return matrixToArray(input, fromRow, rows, 0, input[0].length); } /** * Converts a 2 dimensional array into a single dimension. * Places each column on top of each other. * * @param input * @return Single dimensional array containing the required data */ public static double[] matrixToArray(double[][] input) { return matrixToArray(input, 0, input.length, 0, input[0].length); } }