Skip to content

[numpy] torch.nonzero is similar to np.argwhere not np.nonzero #64502

@kshitij12345

Description

@kshitij12345
import torch
import numpy as np

t = torch.tensor([1, 0, 1, 0])
# t = torch.tensor([[1, 0, 1, 0], [0, 1, 0, 0]])
# t = torch.ones(3, 3, 1)

torch.testing.assert_allclose(torch.nonzero(t), np.argwhere(t.numpy()), rtol=0, atol=0)
torch.testing.assert_allclose(torch.nonzero(t), np.nonzero(t.numpy()), rtol=0, atol=0) # error

cc: @mruberry

cc @mruberry @rgommers @heitorschueroff

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions