Assume that I have a 10-dimensional image in Earth Engine. What I want to know is that in which band, the maximum value of each pixel occurs. I'm actually looking for something like the "Numpy.argmax()" function in Python. How can I do this in Earth Engine using the JavaScript api?


You could maybe do like this:

var image = ee.Image('COPERNICUS/S2_SR/20200101T100319_20200101T100321_T32TQM')
var max = image.reduce(ee.Reducer.max()) // Single band image with max value
var bandIndexes = ee.List.sequence(0, image.bandNames().size().subtract(1))
var maxIndex = ee.ImageCollection(bandIndexes
    .map(function (i) {
      i = ee.Number(i) // When mapping over a list we must cast
      return ee.Image(i) // An image with the index number
        .updateMask(image.select(i).eq(max)) // Mask out if corresponding band isn't max
  .mosaic() // Reduce collection of indexes to a single unmasked index


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.