ArgMax#
ArgMax - 13#
Version
name: ArgMax (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
Computes the indices of the max elements of the input tensor’s element along the provided axis. The resulting tensor has the same rank as the input if keepdims equals 1. If keepdims equals 0, then the resulting tensor has the reduced dimension pruned. If select_last_index is True (default False), the index of the last occurrence of the max is selected if the max appears more than once in the input. Otherwise the index of the first occurrence is selected. The type of the output tensor is integer.
Attributes
axis: The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
keepdims: Keep the reduced dimension or not, default 1 means keep reduced dimension.
select_last_index: Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
Inputs
data (heterogeneous) - T: An input tensor.
Outputs
reduced (heterogeneous) - tensor(int64): Reduced output tensor with integer data type.
Type Constraints
T in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all numeric tensors.
Examples
_no_keepdims
import numpy as np
import onnx
data = np.array([[2, 1], [3, 10]], dtype=np.float32)
axis = 1
keepdims = 0
node = onnx.helper.make_node(
"ArgMax", inputs=["data"], outputs=["result"], axis=axis, keepdims=keepdims
)
# result: [0, 1]
result = argmax_use_numpy(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_no_keepdims_example",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [2, 4]
result = argmax_use_numpy(data, axis=axis, keepdims=keepdims)
expect(
node, inputs=[data], outputs=[result], name="test_argmax_no_keepdims_random"
)
_keepdims
import numpy as np
import onnx
data = np.array([[2, 1], [3, 10]], dtype=np.float32)
axis = 1
keepdims = 1
node = onnx.helper.make_node(
"ArgMax", inputs=["data"], outputs=["result"], axis=axis, keepdims=keepdims
)
# result: [[0], [1]]
result = argmax_use_numpy(data, axis=axis, keepdims=keepdims)
expect(
node, inputs=[data], outputs=[result], name="test_argmax_keepdims_example"
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [2, 1, 4]
result = argmax_use_numpy(data, axis=axis, keepdims=keepdims)
expect(
node, inputs=[data], outputs=[result], name="test_argmax_keepdims_random"
)
_default_axes_keepdims
import numpy as np
import onnx
data = np.array([[2, 1], [3, 10]], dtype=np.float32)
keepdims = 1
node = onnx.helper.make_node(
"ArgMax", inputs=["data"], outputs=["result"], keepdims=keepdims
)
# result: [[1, 1]]
result = argmax_use_numpy(data, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_default_axis_example",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [1, 3, 4]
result = argmax_use_numpy(data, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_default_axis_random",
)
_negative_axis_keepdims
import numpy as np
import onnx
data = np.array([[2, 1], [3, 10]], dtype=np.float32)
axis = -1
keepdims = 1
node = onnx.helper.make_node(
"ArgMax", inputs=["data"], outputs=["result"], axis=axis, keepdims=keepdims
)
# result: [[0], [1]]
result = argmax_use_numpy(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_negative_axis_keepdims_example",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [2, 3, 1]
result = argmax_use_numpy(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_negative_axis_keepdims_random",
)
_no_keepdims_select_last_index
import numpy as np
import onnx
data = np.array([[2, 2], [3, 10]], dtype=np.float32)
axis = 1
keepdims = 0
node = onnx.helper.make_node(
"ArgMax",
inputs=["data"],
outputs=["result"],
axis=axis,
keepdims=keepdims,
select_last_index=True,
)
# result: [1, 1]
result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_no_keepdims_example_select_last_index",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [2, 4]
result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_no_keepdims_random_select_last_index",
)
_keepdims_select_last_index
import numpy as np
import onnx
data = np.array([[2, 2], [3, 10]], dtype=np.float32)
axis = 1
keepdims = 1
node = onnx.helper.make_node(
"ArgMax",
inputs=["data"],
outputs=["result"],
axis=axis,
keepdims=keepdims,
select_last_index=True,
)
# result: [[1], [1]]
result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_keepdims_example_select_last_index",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [2, 1, 4]
result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_keepdims_random_select_last_index",
)
_default_axes_keepdims_select_last_index
import numpy as np
import onnx
data = np.array([[2, 2], [3, 10]], dtype=np.float32)
keepdims = 1
node = onnx.helper.make_node(
"ArgMax",
inputs=["data"],
outputs=["result"],
keepdims=keepdims,
select_last_index=True,
)
# result: [[1, 1]]
result = argmax_use_numpy_select_last_index(data, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_default_axis_example_select_last_index",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [1, 3, 4]
result = argmax_use_numpy_select_last_index(data, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_default_axis_random_select_last_index",
)
_negative_axis_keepdims_select_last_index
import numpy as np
import onnx
data = np.array([[2, 2], [3, 10]], dtype=np.float32)
axis = -1
keepdims = 1
node = onnx.helper.make_node(
"ArgMax",
inputs=["data"],
outputs=["result"],
axis=axis,
keepdims=keepdims,
select_last_index=True,
)
# result: [[1], [1]]
result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_negative_axis_keepdims_example_select_last_index",
)
data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)
# result's shape: [2, 3, 1]
result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)
expect(
node,
inputs=[data],
outputs=[result],
name="test_argmax_negative_axis_keepdims_random_select_last_index",
)
ArgMax - 12#
Version
name: ArgMax (GitHub)
domain: main
since_version: 12
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 12.
Summary
Computes the indices of the max elements of the input tensor’s element along the provided axis. The resulting tensor has the same rank as the input if keepdims equals 1. If keepdims equal 0, then the resulting tensor has the reduced dimension pruned. If select_last_index is True (default False), the index of the last occurrence of the max is selected if the max appears more than once in the input. Otherwise the index of the first occurrence is selected. The type of the output tensor is integer.
Attributes
axis: The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
keepdims: Keep the reduced dimension or not, default 1 means keep reduced dimension.
select_last_index: Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
Inputs
data (heterogeneous) - T: An input tensor.
Outputs
reduced (heterogeneous) - tensor(int64): Reduced output tensor with integer data type.
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all numeric tensors.
ArgMax - 11#
Version
name: ArgMax (GitHub)
domain: main
since_version: 11
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 11.
Summary
Computes the indices of the max elements of the input tensor’s element along the provided axis. The resulting tensor has the same rank as the input if keepdims equals 1. If keepdims equal 0, then the resulting tensor has the reduced dimension pruned. The type of the output tensor is integer.
Attributes
axis: The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
keepdims: Keep the reduced dimension or not, default 1 means keep reduced dimension.
Inputs
data (heterogeneous) - T: An input tensor.
Outputs
reduced (heterogeneous) - tensor(int64): Reduced output tensor with integer data type.
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all numeric tensors.
ArgMax - 1#
Version
name: ArgMax (GitHub)
domain: main
since_version: 1
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 1.
Summary
Computes the indices of the max elements of the input tensor’s element along the provided axis. The resulting tensor has the same rank as the input if keepdims equals 1. If keepdims equal 0, then the resulted tensor have the reduced dimension pruned. The type of the output tensor is integer.
Attributes
axis: The axis in which to compute the arg indices.
keepdims: Keep the reduced dimension or not, default 1 means keep reduced dimension.
Inputs
data (heterogeneous) - T: An input tensor.
Outputs
reduced (heterogeneous) - tensor(int64): Reduced output tensor with integer data type.
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all numeric tensors.