AttributeError: module 'torch' has no attribute 'unravel_index'

Hi, I tried to use torch.unravel_index to find the original indices from the flattened tensor, but there was an error as below:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[61], line 1
----> 1 torch.unravel_index

File /scratch/r902a02/.conda/envs/PyG_scratch1/lib/python3.9/site-packages/torch/__init__.py:1833, in __getattr__(name)
   1830     import importlib
   1831     return importlib.import_module(f".{name}", __name__)
-> 1833 raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

AttributeError: module 'torch' has no attribute 'unravel_index'

But I found that there was a documentation about it in here.
How can I use torch.unravel_index?

It works for me:

torch.unravel_index
Out[40]: <function torch.functional.unravel_index(indices: torch.Tensor, shape: Union[int, Sequence[int], torch.Size]) -> Tuple[torch.Tensor, ...]>

using torch==2.4.0.dev20240506+cu124.

1 Like