ee.Array.argmax
Returns the position, as a list of indices in each array axis, of the maximum value in an array, or null if the array is empty. If there are multiple occurrences of the maximum, returns the position of the first.
Usage | Returns |
---|
Array.argmax() | List |
Argument | Type | Details |
---|
this: array | Array | |
Examples
// Return the position of the maximum value in each dimension.
// Returns null if the array is empty.
print(ee.Array([], ee.PixelType.int8()).argmax()); // null
print(ee.Array([9]).argmax()); // [0]
print(ee.Array([0, -1, 2, 1]).argmax()); // [2]
print(ee.Array([[3, 4, 2], [6, 5, 7]]).argmax()); // [1, 2]
// Returns the first occurrence of the maximum.
print(ee.Array([1, 1, 1, 9, 9, 9]).argmax()); // [3]
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
# Return the position of the maximum value in each dimension.
# Returns null if the array is empty.
display(ee.Array([], ee.PixelType.int8()).argmax()) # None
display(ee.Array([9]).argmax()) # [0]
display(ee.Array([0, -1, 2, 1]).argmax()) # [2]
display(ee.Array([[3, 4, 2], [6, 5, 7]]).argmax()) # [1, 2]
# Returns the first occurrence of the maximum.
display(ee.Array([1, 1, 1, 9, 9, 9]).argmax()) # [3]
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`Array.argmax()` returns the position of the maximum value within an array as a list of indices."],["If multiple maximum values exist, the function returns the position of the first occurrence."],["An empty array input results in a `null` (JavaScript) or `None` (Python) output."],["The function operates across all dimensions of the input array."]]],["The `argmax()` function finds the position of the maximum value within an array. It returns a list of indices, representing the location in each array dimension. If the array is empty, it returns null. In cases of multiple maximum values, it returns the index of the first occurrence. Usage is `Array.argmax()`, and it takes one array argument. Examples illustrate its behavior with empty, single-value, multi-value, and multi-dimensional arrays.\n"]]