MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / nonzero

Function nonzero

monai/transforms/utils_pytorch_numpy_unification.py:189–200  ·  view source on GitHub ↗

`np.nonzero` with equivalent implementation for torch. Args: x: array/tensor. Returns: Index unravelled for given shape

(x: NdarrayOrTensor)

Source from the content-addressed store, hash-verified

187
188
189def nonzero(x: NdarrayOrTensor) -> NdarrayOrTensor:
190 """`np.nonzero` with equivalent implementation for torch.
191
192 Args:
193 x: array/tensor.
194
195 Returns:
196 Index unravelled for given shape
197 """
198 if isinstance(x, np.ndarray):
199 return np.nonzero(x)[0]
200 return torch.nonzero(x).flatten()
201
202
203def floor_divide(a: NdarrayOrTensor, b) -> NdarrayOrTensor:

Callers 2

map_binary_to_indicesFunction · 0.90
map_classes_to_indicesFunction · 0.90

Calls 1

flattenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…