Re: Easy question? [message #16318] |
Wed, 14 July 1999 00:00 |
colinr
Messages: 30 Registered: July 1999
|
Member |
|
|
On 14 Jul 1999 13:55:02 GMT,
Stein Vidar Hagfors Haugan <steinhh@ulrik.uio.no> wrote:
>
> Hi Colin,
>
> How about some in-house advice:
>
> a = rebin(reform(v,1,1,nk),ni,nj,nk)
>
> Although various matrix multiplications always seem to be
> suggested as the answer to such questions, I find the above
> solution a lot easier to grasp intuitively, and it appears
> to be faster on our platforms (results do vary).
You were out of your office when I came to ask ...
--
Colin Rosenthal
Astrophysics Institute
University of Oslo
|
|
|
Re: Easy question? [message #16319 is a reply to message #16318] |
Wed, 14 July 1999 00:00  |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
Hi Colin,
How about some in-house advice:
a = rebin(reform(v,1,1,nk),ni,nj,nk)
Although various matrix multiplications always seem to be
suggested as the answer to such questions, I find the above
solution a lot easier to grasp intuitively, and it appears
to be faster on our platforms (results do vary).
Regards,
Stein Vidar
|
|
|
Re: Easy question? [message #16320 is a reply to message #16318] |
Wed, 14 July 1999 00:00  |
colinr
Messages: 30 Registered: July 1999
|
Member |
|
|
On Wed, 14 Jul 1999 07:26:09 -0500,
Kenneth P. Bowman <bowman@null.tamu.edu> wrote:
> In article <7mhjl5$bme$1@readme.uio.no>, colin.rosenthal@astro.uio.no wrote:
>
>> If I have an i*j*k array and vector of length k and I want to
>> put the vector in every column of the array how do I do it?
>
> FOR k = 0L, nk-1L DO a[*,*,k] = v[k]
Exactly, but I was hoping for a "fast" way of doing it without a loop -
some sort of clever array declaration with ni and nj which would load
the vector up automatically into an array of the appropriate size.
--
Colin Rosenthal
Astrophysics Institute
University of Oslo
|
|
|
Re: Easy question? [message #16321 is a reply to message #16318] |
Wed, 14 July 1999 00:00  |
bowman
Messages: 121 Registered: September 1991
|
Senior Member |
|
|
In article <7mhjl5$bme$1@readme.uio.no>, colin.rosenthal@astro.uio.no wrote:
> If I have an i*j*k array and vector of length k and I want to
> put the vector in every column of the array how do I do it?
FOR k = 0L, nk-1L DO a[*,*,k] = v[k]
> More specifically, I have a 3-d array and wish to compute the average
> value of the array over two of the dimensions and store the result in
> a 3-d array of the same size as the original.
Do you mean "store the result in a *2-D* array"? If so, then
a_mean = TOTAL(a, 3)/nk
If you really mean 3-D, then
a_mean = TOTAL(a, 3)/nk
FOR k = 0L, nk-1L DO a[0L,0L,k] = a_mean
Ken Bowman
|
|
|
Re: Easy question? [message #16323 is a reply to message #16318] |
Wed, 14 July 1999 00:00  |
morisset
Messages: 17 Registered: October 1997
|
Junior Member |
|
|
Hello,
To get the vector of the mean over 2 dimensions, use total, like:
tab = findgen(3,3,3)
print,total(total(tab,1),1)
Play with the indices to mean over the dimension you want
(don't forget to divide by the product of the dimensions ;-).
Perhaps the order influences the speed if your tab doesn't have
the same dimensions?
To transform the 1D into 3D, first go to 2D, using:
tab2 = total(total(tab,1),1) # replicate(1,3)
tab2 = replicate(1,3) # total(total(tab,1),1)
or:
tab2 = replicate(1,3) ## total(total(tab,1),1)
tab2 = total(total(tab,1),1) ## replicate(1,3)
I don't know which of both is the quickest.
From 2D to 3D, I don't know without loop:
tab3 = fltarr(3,3,3,/nozero)
for i = 0,2 do tab3[*,*,i] = tab2
It's important to have the *'s as the first indices.
Hope it's help.
Christophe.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
|
|
|