.. _l-onnx-doc-NonZero: ======= NonZero ======= .. contents:: :local: .. _l-onnx-op-nonzero-13: NonZero - 13 ============ **Version** * **name**: `NonZero (GitHub) `_ * **domain**: **main** * **since_version**: **13** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 13**. **Summary** 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** (heterogeneous) - **T**: input **Outputs** * **Y** (heterogeneous) - **tensor(int64)**: output **Type Constraints** * **T** in ( 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) ): Constrain to all tensor types. **Examples** **default** :: node = onnx.helper.make_node( "NonZero", inputs=["condition"], outputs=["result"], ) condition = np.array([[1, 0], [1, 1]], dtype=bool) result = np.array( np.nonzero(condition), dtype=np.int64 ) # expected output [[0, 1, 1], [0, 0, 1]] expect(node, inputs=[condition], outputs=[result], name="test_nonzero_example") **Differences** .. raw:: html
00Returns the indices of the elements that are non-zeroReturns the indices of the elements that are non-zero
11(in row-major order - by dimension).(in row-major order - by dimension).
22NonZero behaves similar to numpy.nonzero:NonZero behaves similar to numpy.nonzero:
33https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html,https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html,
44but for scalar input, NonZero produces output shape (0, N) instead of (1, N), which is different from Numpy's behavior.but for scalar input, NonZero produces output shape (0, N) instead of (1, N), which is different from Numpy's behavior.
55
66**Inputs****Inputs**
77
88* **X** (heterogeneous) - **T**:* **X** (heterogeneous) - **T**:
99 input input
1010
1111**Outputs****Outputs**
1212
1313* **Y** (heterogeneous) - **tensor(int64)**:* **Y** (heterogeneous) - **tensor(int64)**:
1414 output output
1515
1616**Type Constraints****Type Constraints**
1717
1818* **T** in (* **T** in (
19 tensor(bfloat16),
1920 tensor(bool), tensor(bool),
2021 tensor(complex128), tensor(complex128),
2122 tensor(complex64), tensor(complex64),
2223 tensor(double), tensor(double),
2324 tensor(float), tensor(float),
2425 tensor(float16), tensor(float16),
2526 tensor(int16), tensor(int16),
2627 tensor(int32), tensor(int32),
2728 tensor(int64), tensor(int64),
2829 tensor(int8), tensor(int8),
2930 tensor(string), tensor(string),
3031 tensor(uint16), tensor(uint16),
3132 tensor(uint32), tensor(uint32),
3233 tensor(uint64), tensor(uint64),
3334 tensor(uint8) tensor(uint8)
3435 ): ):
3536 Constrain to all tensor types. Constrain to all tensor types.
.. _l-onnx-op-nonzero-9: NonZero - 9 =========== **Version** * **name**: `NonZero (GitHub) `_ * **domain**: **main** * **since_version**: **9** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 9**. **Summary** 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** (heterogeneous) - **T**: input **Outputs** * **Y** (heterogeneous) - **tensor(int64)**: output **Type Constraints** * **T** in ( 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) ): Constrain to all tensor types.