-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I reorder tensors in place like x[:,:,:,[2,0,1]]
In PyTorch?
#2647
Comments
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.
The text was updated successfully, but these errors were encountered: