Several maxima/minima in 2D array

dear experts:
I wonder if there is a way to find several minima and maxima in a 2D array (TH2, TGraph2D).

I am aware that this would return the index of the maximum

Double_t *z={1,2,3}

I notice that TMath::LocMax may return a Iterator type object, but I have failed to find an example.

In principle I’d like to know if there is a way to obtain something like

TIter iter = TMath::LocMax(myArray)

so if:

Double_t *z={1,2,3,2,2,3}

TIter *iter will have a list of indexes 3 and 6

More generally if there is a straight way to get local minimum/maximum in a 2D diagram or graph

thanks in advance,