# Reverse the elements of a column of a matrix in ND4J

**URL:** <https://community.konduit.ai/t/reverse-the-elements-of-a-column-of-a-matrix-in-nd4j/807>\
**Category:** ND4J\
**Created:** [August 21, 2020, 7:51am UTC](https://community.konduit.ai/t/reverse-the-elements-of-a-column-of-a-matrix-in-nd4j/807 "2020-08-21T07:51:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirshamaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/amirshamaei/32/100_2.png) [@amirshamaei](https://community.konduit.ai/u/amirshamaei)\
**Post date:** [August 21, 2020, 7:51am UTC](https://community.konduit.ai/t/reverse-the-elements-of-a-column-of-a-matrix-in-nd4j/807/1 "2020-08-21T07:51:30Z")

</div>

I do not know it is right to share with the community about a problem and also share your solution (if it is not, remove my topic)  
However, I was trying to rewrite this line of python code in JAVA with the ND4j library.

```auto
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

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

```

finally, I solved my problem in a very nasty way. However, if you come with a robust answer, I will appreciate it.

```auto
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));

```
