NonZero#
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
0 | 0 | Returns the indices of the elements that are non-zero | Returns the indices of the elements that are non-zero |
1 | 1 | (in row-major order - by dimension). | (in row-major order - by dimension). |
2 | 2 | NonZero behaves similar to numpy.nonzero: | NonZero behaves similar to numpy.nonzero: |
3 | 3 | https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, | https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, |
4 | 4 | but 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. |
5 | 5 |
|
|
6 | 6 | **Inputs** | **Inputs** |
7 | 7 |
|
|
8 | 8 | * **X** (heterogeneous) - **T**: | * **X** (heterogeneous) - **T**: |
9 | 9 | input | input |
10 | 10 |
|
|
11 | 11 | **Outputs** | **Outputs** |
12 | 12 |
|
|
13 | 13 | * **Y** (heterogeneous) - **tensor(int64)**: | * **Y** (heterogeneous) - **tensor(int64)**: |
14 | 14 | output | output |
15 | 15 |
|
|
16 | 16 | **Type Constraints** | **Type Constraints** |
17 | 17 |
|
|
18 | 18 | * **T** in ( | * **T** in ( |
19 | tensor(bfloat16), | ||
19 | 20 | tensor(bool), | tensor(bool), |
20 | 21 | tensor(complex128), | tensor(complex128), |
21 | 22 | tensor(complex64), | tensor(complex64), |
22 | 23 | tensor(double), | tensor(double), |
23 | 24 | tensor(float), | tensor(float), |
24 | 25 | tensor(float16), | tensor(float16), |
25 | 26 | tensor(int16), | tensor(int16), |
26 | 27 | tensor(int32), | tensor(int32), |
27 | 28 | tensor(int64), | tensor(int64), |
28 | 29 | tensor(int8), | tensor(int8), |
29 | 30 | tensor(string), | tensor(string), |
30 | 31 | tensor(uint16), | tensor(uint16), |
31 | 32 | tensor(uint32), | tensor(uint32), |
32 | 33 | tensor(uint64), | tensor(uint64), |
33 | 34 | tensor(uint8) | tensor(uint8) |
34 | 35 | ): | ): |
35 | 36 | Constrain to all tensor types. | Constrain to all tensor types. |
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.