javadl4jnd4j

how can I reverse the elements of a column of a matrix in ND4J?


I am trying to rewrite this line of python code in JAVA with ND4j library.

data[index_odd] = tmp[::-1,:]

It reverses the column's elements. (in other words, the order of rows) I used this line but apparently it just works when end>begin

INDArrayIndex rev_idx = NDArrayIndex.interval(10, 1);

I appreciate your help in advance


Solution

  • I solved my problem in a very nasty way :)) I am going to share it with you. However, if you come with a robust answer, I will appreciate it.

    int[] idx = new int[(int) OBJ_imag.shape()[0]];
    for(int i = 0 ; i<OBJ_imag.shape()[0] ; i ++)
        idx[i] = (int) (OBJ_imag.shape()[0] - i -1);
    imag.put(indx, OBJ_imag.getRows(idx));