comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: 2d min
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: 2d min [message #74362] Thu, 13 January 2011 09:07
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jan 13, 8:57 am, chris <rog...@googlemail.com> wrote:
> On 13 Jan., 14:11, Gray <grayliketheco...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On Jan 13, 7:26 am, Gray <grayliketheco...@gmail.com> wrote:
>
>>> On Jan 13, 2:18 am, chris <rog...@googlemail.com> wrote:
>
>>>> On 12 Jan., 23:21, Gray <grayliketheco...@gmail.com> wrote:
>
>>>> > Hi all,
>
>>>> > I have a 3d array, NxNxM.  What I would like is to find the minimum of
>>>> > each NxN slice, and note the index of the minimum in the slice.  I can
>>>> > find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
>>>> > I'm not sure how to turn those two index arrays into the indices that
>>>> > I need.  Help...?
>
>>>> > Thanks!
>
>>>> > --Gray
>
>>>> Hi,
>>>> maybe I missed something, but why don't you use something like this:
>
>>>> IDL> a=randomn(seed,10,10,5)
>>>> IDL> min=min(a,dimension=3,ind)
>>>> IDL> help,min,ind
>>>> MIN             FLOAT     = Array[10, 10]
>>>> IND             LONG64    = Array[10, 10]
>>>> IDL> ind2=array_indices(size(a,/dimensions),ind,/dimensions)
>>>> IDL> help,ind2
>>>> IND2            LONG64    = Array[3, 100]
>
>>>> Is array_indices really to slow with the dimension keyword?
>
>>>> Cheers
>
>>>> CR
>
>>> This gets me a NxN array of minima... I want a vector of minima of
>>> length M (so the minimum in each plane).
>
>> OK, for anyone else, here's what you have to do.
>
>> IDL> a = randomu(seed,10,10,100)
>> IDL> minima = min(min(a,ind1,dim=1),ind2,dim=2)
>> IDL> ind1 -= rebin(indgen(1,100)*10^2.,10,100)
>> IDL> ind2 -= (indgen(100)*10)
>> IDL> xind = ind1[ind2,indgen(100)] mod 10
>> IDL> yind = ind2
>
>> You have to use ind2 to find the right elements of ind1.  Since you
>> get 1d indices from min, you need to subtract off N^2 or N to talk
>> about each plane individually.  The reason I wanted to vectorize is
>> that my actual M is ~20k.
>
> Ok, and this one?
>
> t0=systime(1)
> a=randomu(seed,100l,100l,10000l)
> mins=min(reform(a,100l*100l,10000l,/over),ind,dimension=1)
> a=reform(a,100l,100l,10000l,/over) ;if you need this...
> help,ind,a &print,systime(1)-t0
>
> IND             LONG64    = Array[10000]
> A               FLOAT     = Array[100, 100, 10000]
>        1.9180000
> Maybe you can also use Thread Pool Keywords together with min.
>
> Cheers
> CR

Ooh, reforming so that the first 2 dimensions become 1 that I can min
over... I didn't think about that possibility! Either way works, I
guess.
Re: 2d min [message #74368 is a reply to message #74362] Thu, 13 January 2011 05:57 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 13 Jan., 14:11, Gray <grayliketheco...@gmail.com> wrote:
> On Jan 13, 7:26 am, Gray <grayliketheco...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On Jan 13, 2:18 am, chris <rog...@googlemail.com> wrote:
>
>>> On 12 Jan., 23:21, Gray <grayliketheco...@gmail.com> wrote:
>
>>>> Hi all,
>
>>>> I have a 3d array, NxNxM.  What I would like is to find the minimum of
>>>> each NxN slice, and note the index of the minimum in the slice.  I can
>>>> find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
>>>> I'm not sure how to turn those two index arrays into the indices that
>>>> I need.  Help...?
>
>>>> Thanks!
>
>>>> --Gray
>
>>> Hi,
>>> maybe I missed something, but why don't you use something like this:
>
>>> IDL> a=randomn(seed,10,10,5)
>>> IDL> min=min(a,dimension=3,ind)
>>> IDL> help,min,ind
>>> MIN             FLOAT     = Array[10, 10]
>>> IND             LONG64    = Array[10, 10]
>>> IDL> ind2=array_indices(size(a,/dimensions),ind,/dimensions)
>>> IDL> help,ind2
>>> IND2            LONG64    = Array[3, 100]
>
>>> Is array_indices really to slow with the dimension keyword?
>
>>> Cheers
>
>>> CR
>
>> This gets me a NxN array of minima... I want a vector of minima of
>> length M (so the minimum in each plane).
>
> OK, for anyone else, here's what you have to do.
>
> IDL> a = randomu(seed,10,10,100)
> IDL> minima = min(min(a,ind1,dim=1),ind2,dim=2)
> IDL> ind1 -= rebin(indgen(1,100)*10^2.,10,100)
> IDL> ind2 -= (indgen(100)*10)
> IDL> xind = ind1[ind2,indgen(100)] mod 10
> IDL> yind = ind2
>
> You have to use ind2 to find the right elements of ind1.  Since you
> get 1d indices from min, you need to subtract off N^2 or N to talk
> about each plane individually.  The reason I wanted to vectorize is
> that my actual M is ~20k.

Ok, and this one?

t0=systime(1)
a=randomu(seed,100l,100l,10000l)
mins=min(reform(a,100l*100l,10000l,/over),ind,dimension=1)
a=reform(a,100l,100l,10000l,/over) ;if you need this...
help,ind,a &print,systime(1)-t0

IND LONG64 = Array[10000]
A FLOAT = Array[100, 100, 10000]
1.9180000
Maybe you can also use Thread Pool Keywords together with min.

Cheers
CR
Re: 2d min [message #74370 is a reply to message #74368] Thu, 13 January 2011 05:11 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jan 13, 7:26 am, Gray <grayliketheco...@gmail.com> wrote:
> On Jan 13, 2:18 am, chris <rog...@googlemail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On 12 Jan., 23:21, Gray <grayliketheco...@gmail.com> wrote:
>
>>> Hi all,
>
>>> I have a 3d array, NxNxM.  What I would like is to find the minimum of
>>> each NxN slice, and note the index of the minimum in the slice.  I can
>>> find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
>>> I'm not sure how to turn those two index arrays into the indices that
>>> I need.  Help...?
>
>>> Thanks!
>
>>> --Gray
>
>> Hi,
>> maybe I missed something, but why don't you use something like this:
>
>> IDL> a=randomn(seed,10,10,5)
>> IDL> min=min(a,dimension=3,ind)
>> IDL> help,min,ind
>> MIN             FLOAT     = Array[10, 10]
>> IND             LONG64    = Array[10, 10]
>> IDL> ind2=array_indices(size(a,/dimensions),ind,/dimensions)
>> IDL> help,ind2
>> IND2            LONG64    = Array[3, 100]
>
>> Is array_indices really to slow with the dimension keyword?
>
>> Cheers
>
>> CR
>
> This gets me a NxN array of minima... I want a vector of minima of
> length M (so the minimum in each plane).

OK, for anyone else, here's what you have to do.

IDL> a = randomu(seed,10,10,100)
IDL> minima = min(min(a,ind1,dim=1),ind2,dim=2)
IDL> ind1 -= rebin(indgen(1,100)*10^2.,10,100)
IDL> ind2 -= (indgen(100)*10)
IDL> xind = ind1[ind2,indgen(100)] mod 10
IDL> yind = ind2

You have to use ind2 to find the right elements of ind1. Since you
get 1d indices from min, you need to subtract off N^2 or N to talk
about each plane individually. The reason I wanted to vectorize is
that my actual M is ~20k.
Re: 2d min [message #74371 is a reply to message #74370] Thu, 13 January 2011 04:26 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jan 13, 2:18 am, chris <rog...@googlemail.com> wrote:
> On 12 Jan., 23:21, Gray <grayliketheco...@gmail.com> wrote:
>
>> Hi all,
>
>> I have a 3d array, NxNxM.  What I would like is to find the minimum of
>> each NxN slice, and note the index of the minimum in the slice.  I can
>> find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
>> I'm not sure how to turn those two index arrays into the indices that
>> I need.  Help...?
>
>> Thanks!
>
>> --Gray
>
> Hi,
> maybe I missed something, but why don't you use something like this:
>
> IDL> a=randomn(seed,10,10,5)
> IDL> min=min(a,dimension=3,ind)
> IDL> help,min,ind
> MIN             FLOAT     = Array[10, 10]
> IND             LONG64    = Array[10, 10]
> IDL> ind2=array_indices(size(a,/dimensions),ind,/dimensions)
> IDL> help,ind2
> IND2            LONG64    = Array[3, 100]
>
> Is array_indices really to slow with the dimension keyword?
>
> Cheers
>
> CR

This gets me a NxN array of minima... I want a vector of minima of
length M (so the minimum in each plane).
Re: 2d min [message #74373 is a reply to message #74371] Wed, 12 January 2011 23:18 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 12 Jan., 23:21, Gray <grayliketheco...@gmail.com> wrote:
> Hi all,
>
> I have a 3d array, NxNxM.  What I would like is to find the minimum of
> each NxN slice, and note the index of the minimum in the slice.  I can
> find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
> I'm not sure how to turn those two index arrays into the indices that
> I need.  Help...?
>
> Thanks!
>
> --Gray

Hi,
maybe I missed something, but why don't you use something like this:

IDL> a=randomn(seed,10,10,5)
IDL> min=min(a,dimension=3,ind)
IDL> help,min,ind
MIN FLOAT = Array[10, 10]
IND LONG64 = Array[10, 10]
IDL> ind2=array_indices(size(a,/dimensions),ind,/dimensions)
IDL> help,ind2
IND2 LONG64 = Array[3, 100]

Is array_indices really to slow with the dimension keyword?

Cheers

CR
Re: 2d min [message #74378 is a reply to message #74373] Wed, 12 January 2011 15:44 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gray writes:

> Yes, but that will be slow compared to a vectorized solution, is my
> guess.

I learned from Matt Savoie that looking for vectorized solutions
before you needed to was a fool's errand. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: 2d min [message #74379 is a reply to message #74378] Wed, 12 January 2011 15:06 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jan 12, 5:45 pm, "Kenneth P. Bowman" <k-bow...@null.edu> wrote:
> In article
> < e707ce03-19e9-4ee5-9976-aa4c2d6f3...@f35g2000vbl.googlegroup s.com >,
>
>  Gray <grayliketheco...@gmail.com> wrote:
>> I have a 3d array, NxNxM.  What I would like is to find the minimum of
>> each NxN slice, and note the index of the minimum in the slice.  I can
>> find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
>> I'm not sure how to turn those two index arrays into the indices that
>> I need.  Help...?
>
> You could just loop over the M index and process each 2-D slice.
> ARRAY_INDICES will get you the index within each slice.
>
> Ken Bowman
Yes, but that will be slow compared to a vectorized solution, is my
guess.
Re: 2d min [message #74380 is a reply to message #74379] Wed, 12 January 2011 14:45 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article
<e707ce03-19e9-4ee5-9976-aa4c2d6f3f7a@f35g2000vbl.googlegroups.com>,
Gray <graylikethecolor@gmail.com> wrote:

> I have a 3d array, NxNxM. What I would like is to find the minimum of
> each NxN slice, and note the index of the minimum in the slice. I can
> find my minimum by doing min(min(array,ind1,dim=1),dim=1,ind2), but
> I'm not sure how to turn those two index arrays into the indices that
> I need. Help...?

You could just loop over the M index and process each 2-D slice.
ARRAY_INDICES will get you the index within each slice.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: r_correlate; get "loop limit expression too large" error with /Kendall
Next Topic: Efficient finding of locations where two 'on' pixels are next to one another

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:17:07 PDT 2025

Total time taken to generate the page: 0.00574 seconds