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

Home » Public Forums » archive » Re: Multi-dimensions without for loop ?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Multi-dimensions without for loop ? [message #38763 is a reply to message #38762] Thu, 25 March 2004 06:09 Go to previous messageGo to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Emmanuel Christophe wrote:
> Hi,
>
> I'm trying to optimize some IDL code, removing for loops.
>
> I'm using the mean function to get the average of each line (this is for
> the example, could be another function). From a 2 dimensional array, I
> want to remove the mean of each column.
>
> Here is a sample using a loop:
> --------------------------------
> for j=0,size-1 do begin
> vect=data[j,*]
> datac[j,*]=vect-mean(vect)
> endfor
> --------------------------------
>
> How to do it in one instruction: if i'm using something like
> 'mean(data)', i'll get the average for the whole array, and not line by
> line.
>
> the instruction 'total' give me something similar to what I want:
> 'total(data,1)' will make the sum in only one direction.
>
> How to get that with ordinary function ? and is it possible ? I'm
> thinking of something like 'data[0:size-1,*]'...
>

Hello,

You can do it without a loop, but unfortunately not with the built-in
statistics routines.

IDL> data = Findgen(4,6)
IDL> colTotal = TOTAL(data,2)
IDL> dim = Size(data, /dim)
IDL> colMean = Rebin(colTotal/dim[1], dim)
IDL> newData = data-colMean

But you could write your own routine to add the neat dimension handling
to MEAN, MOMENT, etc that you already get with TOTAL, MAX, etc.

Ben
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: not only google
Next Topic: Image structure

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

Current Time: Sun Nov 30 15:06:29 PST 2025

Total time taken to generate the page: 0.32166 seconds