Re: Strange array division problem [message #66277] |
Wed, 06 May 2009 20:08 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Dave Klassen writes:
> Hmmm...really?
> IDL> a=3D[[2,1],[3,4]]
> IDL> print,a
> 2 1
> 3 4
> IDL> v=3D[5,6]
> IDL> print,v
> 5 6
> IDL> print,a##v
> 16
> 39
> Which leads me to my original thought.
>
> But, then again:
> IDL> print,a#v
> 28 29
>
> So I guess IDL figures a vector is whatever it need to be...?
I think a thorough reading the the Dimensional Juggling
and Array Concatenation tutorials should clear up any
confusion:
http://www.dfanning.com/tips/rebin_magic.html
http://www.dfanning.com/tips/array_concatenation.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Strange array division problem [message #66278 is a reply to message #66277] |
Wed, 06 May 2009 19:03  |
David Klassen
Messages: 27 Registered: December 2004
|
Junior Member |
|
|
On May 5, 9:07 am, David Fanning <n...@dfanning.com> wrote:
> Dave Klassen writes:
>> This seems to do it (well, without the transpose---I assume because
>> IDL thinks of standard vectors as columns...?).
>
> No, IDL does not think of standard vectors as columns.
Hmmm...really?
IDL> a=[[2,1],[3,4]]
IDL> print,a
2 1
3 4
IDL> v=[5,6]
IDL> print,v
5 6
IDL> print,a##v
16
39
Which leads me to my original thought.
But, then again:
IDL> print,a#v
28 29
So I guess IDL figures a vector is whatever it need to be...?
Interestingly:
IDL> print,a##transpose(v)
16
39
But:
IDL> print,a#transpose(v)
% Operands of matrix multiply have incompatible dimensions: A,
<INT
Array[1, 2]>.
% Execution halted at: $MAIN$
So that's confusing.
> P.S. I'd give that result an extra pair of eyeballs
> before you turn it in for a final grade. :-)
Well, I didn't get extra eyes, but I did look long and hard, several
times, at the output and it looks like what I expect.
|
|
|
Re: Strange array division problem [message #66284 is a reply to message #66278] |
Tue, 05 May 2009 14:23  |
cgguido
Messages: 195 Registered: August 2005
|
Senior Member |
|
|
On May 5, 8:07 am, David Fanning <n...@dfanning.com> wrote:
>
> P.S. I'd give that result an extra pair of eyeballs
> before you turn it in for a final grade. :-)
>
yes yes... especially because I can get dimensions mixed up faster
then I can say...uhmm... transpose.
|
|
|
Re: Strange array division problem [message #66288 is a reply to message #66284] |
Tue, 05 May 2009 06:07  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Dave Klassen writes:
> This seems to do it (well, without the transpose---I assume because
> IDL thinks of standard vectors as columns...?).
No, IDL does not think of standard vectors as columns.
Cheers,
David
P.S. I'd give that result an extra pair of eyeballs
before you turn it in for a final grade. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Strange array division problem [message #66289 is a reply to message #66288] |
Tue, 05 May 2009 05:44  |
David Klassen
Messages: 27 Registered: December 2004
|
Junior Member |
|
|
On May 4, 7:52 pm, gianguido.cia...@gmail.com wrote:
>> how about:
>
>> a3d /= rebin(xcounts,z,y,x)
>
> oops:
>
> a3d /= transpose(rebin(xcounts, x, y, z), [1,2,0])
This seems to do it (well, without the transpose---I assume because
IDL
thinks of standard vectors as columns...?).
Thanks! And thanks for the tip on /= I never knew about [op]=
assignments.
|
|
|
Re: Strange array division problem [message #66293 is a reply to message #66289] |
Mon, 04 May 2009 16:52  |
cgguido
Messages: 195 Registered: August 2005
|
Senior Member |
|
|
> how about:
>
> a3d /= rebin(xcounts,z,y,x)
oops:
a3d /= transpose(rebin(xcounts, x, y, z), [1,2,0])
depending on how you do things, you may have to switch the 'y' and 'z'
and the '1' and '2'
a=indgen(5)
help, transpose(rebin(a, 5, 10, 10), [2, 1, 0])
;<Expression> INT = Array[10, 10, 5]
now you can divide a3d with a because they have the same dimensions.
|
|
|
Re: Strange array division problem [message #66294 is a reply to message #66293] |
Mon, 04 May 2009 16:35  |
cgguido
Messages: 195 Registered: August 2005
|
Senior Member |
|
|
On May 4, 4:42 pm, David Klassen <klas...@rowan.edu> wrote:
> I'm trying to create an array by reading in 2-d data and putting into
> planes in a 3-d array, however, some of the data is redundant---the 2-
> d data would go into the same plane. In these cases, I want to
> average them so I figure I can just add the data to the current plane
> value, keeping track of how many data arrays go into each plane, then
> just divide the final 3-d array by these counts. But I'm stuck on how
> exactly to implement that.
>
> My 3-d array X columns, Y rows, Z planes and the 2-d array is Z
> columns by Y rows (so I'm "rotating" the data and "sliding" each one
> into a column of the 3-d array---I hope that makes sense). I then
> have a vector, xcounts, that is X elements long and as data go into
> the columns, I increment xcounts[X].
>
> So, when I'm done populating the 3-d array I need to divide each row
> in each plane by the vector xcounts. Is there an easy way to do this
> that doesn't involve me looping through all the points?
how about:
a3d /= rebin(xcounts,z,y,x)
|
|
|