8000 feature request - transform pytorch tensors to numpy array automatically · Issue #16098 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

feature request - transform pytorch tensors to numpy array automatically #16098

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

Closed
danFromTelAviv opened this issue Apr 28, 2020 · 1 comment
Closed

Comments

@danFromTelAviv
Copy link

Hi great people of numpy. I love you for you amazing work.
I use numpy a lot for debugging pytorch. I am somewhat sure I am not the only one.
Pytorch has a beautiful feature that you can use numpy arrays in pytorch like pytorch tensors. I would love to see that same ability in numpy as well.
for example :

np.unique(torch.arange(10))

really it would just mean hiding away

def torch_to_numpy(x):
    return x.cpu().data.numpy()

This would just make the two libraries almost seamless which would be fantastic and would likely advance mankind that much faster.

Thanks,
Dan

@seberg
Copy link
Member
seberg commented Apr 28, 2020

@danFromTelAviv thanks for bringing this up, but NumPy is not really the right place. NumPy knows cannot and must not know anything pytorch. There has been some discussion of implementing np.asarray(tensor, force=True), but for your debugging it would be just the same as using your own little force_array() helper probably.

There is some discussion at PyTorch, and on a NumPy mailing list thread about the np.asarray(tensor, force=True) extension, and pytorch probably will add (or already added) a x.numpy(force=True) to make it less typing for you.

Note that even if force=True argument is added, NumPy functions could not reasonably use it, so it would not actually help in your specific situation.

I am going to close this, but would be very happy to discuss a bit more or if you can weigh in over at PyTorch or the NumPy mailing list!

@seberg seberg closed this as completed Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0