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

Home » Public Forums » archive » Re: array dimensions and subscripts
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: array dimensions and subscripts [message #39199] Tue, 27 April 2004 08:06 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Benjamin Hornberger <benjamin.hornberger@stonybrook.edu> writes:

> Hi all,
>
> I have a 3d data array A (n_columns, n_rows, n_data) where columns and
> rows make up an image and for each pixel in the image I recorded n_data
> different data values.
>
> Then I have a 1d array B with n_data entries, and I want to subtract B
> from A such that for each element in A, the element from B in the
> corresponding data channel is subtracted. Obviously, A-B won't work. I

This has been covered several times. A good place to start is JD's
dimension juggling tutorial
(http://www.dfanning.com/tips/rebin_magic.html).

REBIN/REFORM, which is what you would need to do, is easy enough.
However, it is also straightforward to use a FOR loop. In my own
opinion, if you can do enough subtractions in a single FOR loop
iteration, then it will be fast.

At that stage, it's up to you to decide which method is more elegant
and maintainable.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: array dimensions and subscripts [message #39200 is a reply to message #39199] Tue, 27 April 2004 08:07 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Benjamin Hornberger writes:

> I have a 3d data array A (n_columns, n_rows, n_data) where columns and
> rows make up an image and for each pixel in the image I recorded n_data
> different data values.
>
> Then I have a 1d array B with n_data entries, and I want to subtract B
> from A such that for each element in A, the element from B in the
> corresponding data channel is subtracted. Obviously, A-B won't work. I
> can imagine two ways:
>
> 1. For loop
>
> result = fltarr(n_columns, n_rows, n_data) ;; initialize
> for i=0, n_data-1 do results[*, *, i] = A[*, *, i] - B[i]
>
> 2. Blowing up B to 3d (which I can't manage to do without a for loop
> either)
>
> B1 = fltarr(n_column, n_rows, n_data)
> for i=0, n_data-1 do B1[*, *, i] = B[i]
> result = A - B1
>
> But these solutions don't seem very elegant and efficient to me. Is
> there any way to make it work with a single array operation using the *
> subscript, or something similar?

While you are waiting for an answer, I'd browse the Dimensional
Juggling Tutorial. I have a feeling it is going to be mentioned
somewhere in the answer. :-)

http://www.dfanning.com/tips/rebin_magic.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: array dimensions and subscripts
Next Topic: Keyboard Events on Windows

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

Current Time: Wed Oct 08 17:37:58 PDT 2025

Total time taken to generate the page: 0.00514 seconds