Here you can find the source of permuteRows(double[][] ary, int[] idx)
public static double[][] permuteRows(double[][] ary, int[] idx)
//package com.java2s; //License from project: Apache License public class Main { public static double[][] permuteRows(double[][] ary, int[] idx) { if (ary == null) return null; assert ary.length == idx.length : "Number of rows must match permutation vector length: Got " + ary.length + " != " + idx.length; double[][] res = new double[ary.length][ary[0].length]; for (int i = 0; i < ary.length; i++) res[i] = permute(ary[i], idx); return res; }/*from w w w . j a va2s . c o m*/ public static double[] permute(double[] vec, int[] idx) { if (vec == null) return null; assert vec.length == idx.length : "Length of vector must match permutation vector length: Got " + vec.length + " != " + idx.length; double[] res = new double[vec.length]; for (int i = 0; i < vec.length; i++) res[i] = vec[idx[i]]; return res; } }