Closed i10416 closed 1 year ago
We already have full support of pytorch indexing: #1719 and #1755 . See the demos therein.
To your use case, it can be easily done like the following:
val mg = NDManager.newBaseManager()
val sample = mg.randomNormal(new Shape(1, 10, 10, 3))
val indexArray = mg.create(new int {0, 2, 1});
val newArray = sample.get(new NDIndex(":, :, :, {}"), indexArray));
sample.set(new NDIndex(":, :, :, :"), newArray) // if needed
Ah, I didn't know those PRs. Thanks a lot!
By the way, is there a correspondence table of PyTorch tensor API vs djl tensor API similar to that of numpy vs breeze(see https://github.com/scalanlp/breeze/wiki/Linear-Algebra-Cheat-Sheet)?
And if there isn't, is it helpful to write such comparison as a Wiki or a document?
@i10416 We don't have a corresponding table like that. I could see it being useful though! If you are interested in writing one, you can put it in a markdown document PR and we can add it to our docs near http://docs.djl.ai/master/engines/pytorch/index.html
Given
x
of shape (1, 10, 10, 3), I can reorder( and replace in place) tensors in the specific axis by, for example,x[:,:,:,[2,0,1]]
In PyTorch. How can I achieve the same result using DJL NDArray API?For now, I use the following code.