`np.nonzero` with equivalent implementation for torch. Args: x: array/tensor. Returns: Index unravelled for given shape
(x: NdarrayOrTensor)
| 187 | |
| 188 | |
| 189 | def 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 | |
| 203 | def floor_divide(a: NdarrayOrTensor, b) -> NdarrayOrTensor: |
no test coverage detected
searching dependent graphs…