Where#
Where - 16#
Version
name: Where (GitHub)
domain: main
since_version: 16
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 16.
Summary
Return elements, either from X or Y, depending on condition. Where behaves like [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) with three parameters.
This operator supports multidirectional (i.e., Numpy-style) broadcasting; for more details please check Broadcasting in ONNX.
History - Version 16 adds bfloat16 to the types allowed (for the second and third parameter).
Inputs
condition (heterogeneous) - B: When True (nonzero), yield X, otherwise yield Y
X (heterogeneous) - T: values selected at indices where condition is True
Y (heterogeneous) - T: values selected at indices where condition is False
Outputs
output (heterogeneous) - T: Tensor of shape equal to the broadcasted shape of condition, X, and Y.
Type Constraints
B in ( tensor(bool) ): Constrain to boolean tensors.
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 input and output types to all tensor types (including bfloat).
Examples
long
node = onnx.helper.make_node(
'Where',
inputs=['condition', 'x', 'y'],
outputs=['z'],
)
condition = np.array([[1, 0], [1, 1]], dtype=bool)
x = np.array([[1, 2], [3, 4]], dtype=np.int64)
y = np.array([[9, 8], [7, 6]], dtype=np.int64)
z = np.where(condition, x, y) # expected output [[1, 8], [3, 4]]
expect(node, inputs=[condition, x, y], outputs=[z],
name='test_where_long_example')
Differences
0 | 0 | Return elements, either from X or Y, depending on condition. | Return elements, either from X or Y, depending on condition. |
1 | 1 | Where behaves like | Where behaves like |
2 | 2 | [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) | [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) |
3 | 3 | with three parameters. | with three parameters. |
4 | 4 |
|
|
5 | 5 | This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check Broadcasting in ONNX | This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check Broadcasting in ONNX |
6 | 6 |
|
|
7 | **History** | ||
8 | - Version 16 adds bfloat16 to the types allowed (for the second and third parameter). | ||
9 |
| ||
7 | 10 | **Inputs** | **Inputs** |
8 | 11 |
|
|
9 | 12 | * **condition** (heterogeneous) - **B**: | * **condition** (heterogeneous) - **B**: |
10 | 13 | When True (nonzero), yield X, otherwise yield Y | When True (nonzero), yield X, otherwise yield Y |
11 | 14 | * **X** (heterogeneous) - **T**: | * **X** (heterogeneous) - **T**: |
12 | 15 | values selected at indices where condition is True | values selected at indices where condition is True |
13 | 16 | * **Y** (heterogeneous) - **T**: | * **Y** (heterogeneous) - **T**: |
14 | 17 | values selected at indices where condition is False | values selected at indices where condition is False |
15 | 18 |
|
|
16 | 19 | **Outputs** | **Outputs** |
17 | 20 |
|
|
18 | 21 | * **output** (heterogeneous) - **T**: | * **output** (heterogeneous) - **T**: |
19 | 22 | Tensor of shape equal to the broadcasted shape of condition, X, and | Tensor of shape equal to the broadcasted shape of condition, X, and |
20 | 23 | Y. | Y. |
21 | 24 |
|
|
22 | 25 | **Type Constraints** | **Type Constraints** |
23 | 26 |
|
|
24 | 27 | * **B** in ( | * **B** in ( |
25 | 28 | tensor(bool) | tensor(bool) |
26 | 29 | ): | ): |
27 | 30 | Constrain to boolean tensors. | Constrain to boolean tensors. |
28 | 31 | * **T** in ( | * **T** in ( |
32 | tensor(bfloat16), | ||
29 | 33 | tensor(bool), | tensor(bool), |
30 | 34 | tensor(complex128), | tensor(complex128), |
31 | 35 | tensor(complex64), | tensor(complex64), |
32 | 36 | tensor(double), | tensor(double), |
33 | 37 | tensor(float), | tensor(float), |
34 | 38 | tensor(float16), | tensor(float16), |
35 | 39 | tensor(int16), | tensor(int16), |
36 | 40 | tensor(int32), | tensor(int32), |
37 | 41 | tensor(int64), | tensor(int64), |
38 | 42 | tensor(int8), | tensor(int8), |
39 | 43 | tensor(string), | tensor(string), |
40 | 44 | tensor(uint16), | tensor(uint16), |
41 | 45 | tensor(uint32), | tensor(uint32), |
42 | 46 | tensor(uint64), | tensor(uint64), |
43 | 47 | tensor(uint8) | tensor(uint8) |
44 | 48 | ): | ): |
45 | 49 | Constrain input and output types to all tensor types. |
|
50 | bfloat). |
Where - 9#
Version
name: Where (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
Return elements, either from X or Y, depending on condition. Where behaves like [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) with three parameters.
This operator supports multidirectional (i.e., Numpy-style) broadcasting; for more details please check Broadcasting in ONNX.
Inputs
condition (heterogeneous) - B: When True (nonzero), yield X, otherwise yield Y
X (heterogeneous) - T: values selected at indices where condition is True
Y (heterogeneous) - T: values selected at indices where condition is False
Outputs
output (heterogeneous) - T: Tensor of shape equal to the broadcasted shape of condition, X, and Y.
Type Constraints
B in ( tensor(bool) ): Constrain to boolean tensors.
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 input and output types to all tensor types.