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

Home » Public Forums » archive » arithmetic operation on array
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: arithmetic operation on array [message #85479 is a reply to message #85478] Mon, 12 August 2013 15:22 Go to previous messageGo to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
OK, I'll bite. There are three ways I can think to do this off the top of my head:
1) Do a loop, like Phillip said (what a fantastic name :-) )
2) Rebin, like David said
3) Use the mysterious "add an extra dimension" method ( https://groups.google.com/d/msg/comp.lang.idl-pvwave/Vu9rzqc kBNQ/HvkK_QnJrsgJ and more recently https://groups.google.com/d/msg/comp.lang.idl-pvwave/dM8XXas Eio0/d3__pvX7svMJ)

Here are the sample code I used:

data = RANDOMU(1L, 360, 180, 456)
avg = MEAN(data, DIM=3)
mData1 = FLTARR(360, 180, 456)

tic & for i=0, 455 do mData1[*,*,i] = data[*,*,i] - avg & toc

mData2 = FLTARR(360, 180, 456)

tic & mData2 = data - Rebin(avg, 360, 180, 456) & toc
tic & data = TEMPORARY(data) - Rebin(avg, 360, 180, 456) & toc ;just for completeness

data = RANDOMU(1L, 360, 180, 456) ;redefine data - we changed it above
mData3 = FLTARR(360, 180, 456)

tic & mData3 = data - avg[*, *, 0] & toc

I used mData (modified data) arrays so I can check I get the same answer, regardless of the method.

The four times I get are, in order relative to the above:
% Time elapsed: 0.12749481 seconds.
% Time elapsed: 0.33231401 seconds.
% Time elapsed: 0.33304191 seconds.
% Time elapsed: 0.019619942 seconds.

So, it seems the mysterious extra dimension method is the fastest, by an order of magnitude. Whoa.

For prosperity,
IDL> print, !VERSION
{ x86_64 darwin unix Mac OS X 8.2.2 Jan 23 2013 64 64}
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Coyote Graphics PS/PDF output size/orientation
Next Topic: Not IDL Related Question

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

Current Time: Fri Oct 10 09:59:30 PDT 2025

Total time taken to generate the page: 1.11856 seconds