Re: Subscripts of minimum value in array

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 16 2010 - 15:23:15 MDT

Arlene,

There's no function that will do this directly, but you can use minind or ind, and then use
ind_resolve to "resolve" those indexes to the original array they came from.

If you need *all* the indexes where the minimum occurs, try this:

;
; Create sample multi-dimensioned array.
; The following creates a 3D array of size 2 x 2 x 4.
;
  a = (/(/(/1,2,3,4/), (/5,6,7,8/)/), (/(/9,1,9,8/),(/7,6,1,4/)/)/)

;---Convert to 1D
  a1D = ndtooned(a)
  dsizes_a = dimsizes(a)

;---Get indices where the minimum occurs.
  indices = ind_resolve(ind(a1D.eq.min(a1D)),dsizes_a)
  print(indices)

If you just need the first index, then change the ind_resolve line to:

  indices = ind_resolve(minind(a1D),dsizes_a)

--Mary

On Jun 16, 2010, at 2:26 PM, Arlene Laing wrote:

> Hi everyone,
>
> Does anyone know how to find the subscripts of the minimum value in a
> multidimensional array?
>
> I know about the functions "min" that returns the minimum value and
> "minind" that returns the index of the first occurrence of the minimum
> value. However, those are not appropriate.
>
> Thanks in advance for your help.
>
> Arlene Laing
> ----------------
> NCAR & UCAR/COMET
> laing@ucar.edu
> 303-497-8147
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jun 16 15:23:26 2010

This archive was generated by hypermail 2.1.8 : Wed Jun 16 2010 - 15:28:33 MDT