英文:
how can I reverse the elements of a column of a matrix in ND4J?
问题
我正尝试使用ND4j库将Python代码行转写为JAVA代码:
data.getRow(index_odd).assign(tmp.get(NDArrayIndex.all(), NDArrayIndex.interval(tmp.columns() - 1, -1, 0)));
它会反转列的元素(换句话说,行的顺序)。我使用了以下代码,但显然仅在end > begin时有效:
INDArrayIndex rev_idx = NDArrayIndex.interval(10, 1);
提前感谢您的帮助。
英文:
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
答案1
得分: 0
我用一种非常巧妙的方式解决了我的问题:))
我打算与你分享。然而,如果你能提供一个健壮的答案,我将不胜感激。
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));
英文:
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));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论