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

Home » Public Forums » archive » IDL Way to have a single row/collum act on all rows/collums in an array
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
IDL Way to have a single row/collum act on all rows/collums in an array [message #89540] Fri, 24 October 2014 07:32 Go to next message
JTMHD is currently offline  JTMHD
Messages: 9
Registered: October 2014
Junior Member
Hi Guys,


What I am trying to do is analogous to the following

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
timedistancearray =FINDGEN(3,3)

timezero = timedistancearray(*,0)

timedistance_minustimezero = FLTARR(3,3)

FOR t=0,2 DO timedistance_minustimezero(*,t)=timedistancearray(*,t)-timez ero
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


The thing is in this case the array is HUGE so I don't think the FOR loop would be optimum.

The other thing I thought about was taking the timezero array and changing it into a 2D array of the correct dimensions, e.g.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;

timedistancearray =FINDGEN(3,3)

timezero = timedistancearray(*,0)#MAKE_ARRAY(1, 3, /DOUBLE, VALUE = 1D0)

timedistance_minustimezero = timedistancearray-timezero

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;

But again, this perhaps isn't ideal as it will involve creating an equally huge array to do the operation which will have add to the memory overhead.

I keep hearing that if you want to get good at IDL you have to exploit the array operations properly - what other options do I have here?

Thanks in advance

Jonathan
Re: IDL Way to have a single row/collum act on all rows/collums in an array [message #89541 is a reply to message #89540] Fri, 24 October 2014 07:49 Go to previous messageGo to next message
rryan%stsci.edu is currently offline  rryan%stsci.edu
Messages: 16
Registered: October 2014
Junior Member
Unfortunately, I am unaware of a better way of doing arithmetic of the form

Matrix _DO_SOMETHING_HERE_ vector

where the vector is applied to all the rows/columns of the matrix without looping or beefing up the vector to match the matrix.

Two more things. First a question. How huge is HUGE? What are the real dimensions of the 2 matrices and vectors. Also, do you really need them both in memory? Like, do you need all the past time values in memory at this time?

Second a statement. If the answer is Yes, i need everything at all times. Then doing

a= x# make_array()

is going to be slow. Because the # operator is doing arthimeic. You'll likely be better off using rebin and reform to achieve the same goal.

-Russell



On Friday, October 24, 2014 10:32:43 AM UTC-4, JTMHD wrote:
> Hi Guys,
>
>
> What I am trying to do is analogous to the following
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> timedistancearray =FINDGEN(3,3)
>
> timezero = timedistancearray(*,0)
>
> timedistance_minustimezero = FLTARR(3,3)
>
> FOR t=0,2 DO timedistance_minustimezero(*,t)=timedistancearray(*,t)-timez ero
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> The thing is in this case the array is HUGE so I don't think the FOR loop would be optimum.
>
> The other thing I thought about was taking the timezero array and changing it into a 2D array of the correct dimensions, e.g.
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;
>
> timedistancearray =FINDGEN(3,3)
>
> timezero = timedistancearray(*,0)#MAKE_ARRAY(1, 3, /DOUBLE, VALUE = 1D0)
>
> timedistance_minustimezero = timedistancearray-timezero
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;
>
> But again, this perhaps isn't ideal as it will involve creating an equally huge array to do the operation which will have add to the memory overhead.
>
> I keep hearing that if you want to get good at IDL you have to exploit the array operations properly - what other options do I have here?
>
> Thanks in advance
>
> Jonathan
Re: IDL Way to have a single row/collum act on all rows/collums in an array [message #89542 is a reply to message #89540] Fri, 24 October 2014 08:11 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Friday, October 24, 2014 10:32:43 AM UTC-4, JTMHD wrote:
> Hi Guys,
>
>
> What I am trying to do is analogous to the following
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> timedistancearray =FINDGEN(3,3)
>
> timezero = timedistancearray(*,0)
>
> timedistance_minustimezero = FLTARR(3,3)
>
> FOR t=0,2 DO timedistance_minustimezero(*,t)=timedistancearray(*,t)-timez ero
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> The thing is in this case the array is HUGE so I don't think the FOR loop would be optimum.

1. Looping over 1 dimension is usually fine. The important thing is to do many operations on each iteration, which you are doing in this case.

2. You want to rewrite the equation to avoid use of the asterisk on the left hand side

FOR t=0,2 DO timedistance_minustimezero[0,t]=timedistancearray[*,t]-timez ero

http://www.idlcoyote.com/code_tips/asterisk.html

3. As noted by Russell -- do you need to keep both arrays in memory? If not, then you can write it like this:

FOR t=0,2 DO timedistancearray[0,t]=timedistancearray[*,t]-timezero
Re: IDL Way to have a single row/collum act on all rows/collums in an array [message #89561 is a reply to message #89540] Mon, 27 October 2014 05:13 Go to previous message
JTMHD is currently offline  JTMHD
Messages: 9
Registered: October 2014
Junior Member
Hi Guys

Thanks for the tips. They're fairly big - around 200000 by several thousand depending on how long I run the simulations for, and this will be potentially extended to 2D+t soon (but with less resolution in any given spatial direction).

In the end I've rewrote it so that it doesn't need both in memory, as suggested. I've also avoided the use of the asterisk.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to choose the Language of IDL Workbench on mac os
Next Topic: rescaling draw widgets: is there an easier solution to this?

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

Current Time: Wed Oct 08 07:22:42 PDT 2025

Total time taken to generate the page: 0.47741 seconds