Java Array Permute permuteRows(double[][] ary, int[] idx)

Here you can find the source of permuteRows(double[][] ary, int[] idx)

Description

permute Rows

License

Apache License

Declaration

public static double[][] permuteRows(double[][] ary, int[] idx) 

Method Source Code

//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;
    }
}

Related

  1. permute(T[] array)
  2. permute(T[] values)
  3. permuteArray(int[] array, Integer[] permutation)
  4. permuteCols(double[][] ary, int[] idx)
  5. permuteList(List inList)
  6. permuteVector(float[] indexVector, int rotation)