.. _op_ai_onnx_NonZero: NonZero ======= - **Domain**: ``ai.onnx`` - **Since version**: 13 Returns the indices of the elements that are non-zero (in row-major order - by dimension). NonZero behaves similar to numpy.nonzero: https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, but for scalar input, NonZero produces output shape (0, N) instead of (1, N), which is different from Numpy's behavior. **Inputs** - **X** (*T*): input **Outputs** - **Y** (*tensor(int64)*): output **Type Constraints** - **T**: Constrain to all tensor types. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8). Examples -------- **test_cc_nonzero_1d** .. code-block:: text Node: NonZero(X) -> (Y) .. code-block:: text Inputs: X: shape=(5,), dtype=float32 [ 0., 1., 0., -1., 2.] Outputs: Y: shape=(1, 3), dtype=int64 [[1, 3, 4]] **test_cc_nonzero_2d** .. code-block:: text Node: NonZero(X) -> (Y) .. code-block:: text Inputs: X: shape=(2, 2), dtype=float32 [[1., 0.], [1., 1.]] Outputs: Y: shape=(2, 3), dtype=int64 [[0, 1, 1], [0, 0, 1]] **test_cc_nonzero_bool** .. code-block:: text Node: NonZero(X) -> (Y) .. code-block:: text Inputs: X: shape=(2, 3), dtype=bool [[ True, False, True], [False, True, False]] Outputs: Y: shape=(2, 3), dtype=int64 [[0, 0, 1], [0, 2, 1]] **test_cc_nonzero_example** .. code-block:: text Node: NonZero(condition) -> (result) .. code-block:: text Inputs: condition: shape=(2, 2), dtype=bool [[ True, False], [ True, True]] Outputs: result: shape=(2, 3), dtype=int64 [[0, 1, 1], [0, 0, 1]] **test_cc_nonzero_int64** .. code-block:: text Node: NonZero(X) -> (Y) .. code-block:: text Inputs: X: shape=(2, 3), dtype=int64 [[0, 1, 2], [0, 0, 3]] Outputs: Y: shape=(2, 3), dtype=int64 [[0, 0, 1], [1, 2, 2]] Differences with previous version (9) ------------------------------------- **SchemaDiff**: ``NonZero`` (domain ``'ai.onnx'``) * old version: 9 * new version: 13 * breaking: no **Type constraints:** * changed 'T': added types: ['tensor(bfloat16)'] Version History --------------- - :doc:`Version 9 `