cf.Field.argmax¶

Field.
argmax
(axis=None, unravel=False)[source]¶ Return the indices of the maximum values along an axis.
If no axis is specified then the returned index locates the maximum of the whole data.
In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.
Performance
If the data index is returned as a
tuple
(see the unravel parameter) then all delayed operations are computed.New in version 3.0.0.
See also
 Parameters
 axis: optional
Select the domain axis over which to locate the maximum values, defined by the domain axis that would be selected by passing the given axis to a call of the field construct’s
domain_axis
method. For example, for a value of'X'
, the domain axis construct returned byf.domain_axis('X')
is selected.By default the maximum over the flattened data is located.
 unravel:
bool
, optional If True then when locating the maximum over the whole data, return the location as an integer index for each axis as a
tuple
. By default an index to the flattened array is returned in this case. Ignored if locating the maxima over a subset of the axes.
 Returns
Examples
>>> f = cf.example_field(2) >>> print(f) Field: air_potential_temperature (ncvar%air_potential_temperature)  Data : air_potential_temperature(time(36), latitude(5), longitude(8)) K Cell methods : area: mean Dimension coords: time(36) = [19591216 12:00:00, ..., 19621116 00:00:00] : latitude(5) = [75.0, ..., 75.0] degrees_north : longitude(8) = [22.5, ..., 337.5] degrees_east : air_pressure(1) = [850.0] hPa
Find the T axis indices of the maximum at each XY location:
>>> i = f.argmax('T') >>> print(i.array) [[31 10 2 27 16 7 21 17] [24 34 1 22 28 17 19 13] [20 7 15 21 6 20 8 18] [24 1 7 18 19 6 11 18] [16 8 12 9 12 2 6 17]]
Find the coordinates of the global maximum value, showing that it occurs on 19601116 at location 292.5 degrees east, 45.0 degrees north:
>>> g = f[f.argmax(unravel=True)] >>> print(g) Field: air_potential_temperature (ncvar%air_potential_temperature)  Data : air_potential_temperature(time(1), latitude(1), longitude(1)) K Cell methods : area: mean Dimension coords: time(1) = [19601116 00:00:00] : latitude(1) = [45.0] degrees_north : longitude(1) = [292.5] degrees_east : air_pressure(1) = [850.0] hPa
See
cf.Data.argmax
for further examples.