All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deeplearning4j.util.ArrayUtil Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.deeplearning4j.util;

public class ArrayUtil {

	public static int[] flatten(int[][] arr) {
		int[] ret = new int[arr.length * arr[0].length];
		int count = 0;
		for(int i = 0; i < arr.length; i++)
			for(int j = 0; j < arr[i].length; j++)
				ret[count++] = arr[i][j];
		return ret;
	}
	
	public static double[] flatten(double[][] arr) {
		double[] ret = new double[arr.length * arr[0].length];
		int count = 0;
		for(int i = 0; i < arr.length; i++)
			for(int j = 0; j < arr[i].length; j++)
				ret[count++] = arr[i][j];
		return ret;
	}
	
	public static double[][] toDouble(int[][] arr) {
		double[][] ret = new double[arr.length][arr[0].length];
		for(int i = 0; i < arr.length; i++) {
			for(int j = 0; j < arr[i].length; j++)
				ret[i][j] = arr[i][j];
		}
		return ret;
	}
	
	public static int[] toOutcomeArray(int outcome,int numOutcomes) {
		int[] nums = new int[numOutcomes];
		nums[outcome] = 1;
		return nums;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy