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

Home » Public Forums » archive » Adding x,y events to a 2d array (quickly)
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: Adding x,y events to a 2d array (quickly) [message #86430 is a reply to message #86425] Thu, 07 November 2013 11:27 Go to previous messageGo to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Oliver,

You have a good question, and I think this code illustrates it a little more
plainly, starting each time with an array of zero values:

counts=fltarr(3,3)
counts[[1,1,2],[1,1,2]] ++
Print, 'counts[[1,1,2],[1,1,2]] ++:'
Print, counts

counts=fltarr(3,3)
counts[[1,1,2],[1,1,2]] += 1
Print, 'counts[[1,1,2],[1,1,2]] += 1:'
Print, counts

counts=fltarr(3,3)
counts[[1,1,2],[1,1,2]] += [1,1,1]
Print, 'counts[[1,1,2],[1,1,2]] += [1,1,1]:'
Print, counts

counts=fltarr(3,3)
counts[[1,1,2],[1,1,2]] += [10,20,30]
Print, 'counts[[1,1,2],[1,1,2]] += [10,20,30]:'
Print, counts

The result of this is:

counts[[1,1,2],[1,1,2]] ++:
0.000000 0.000000 0.000000
0.000000 2.00000 0.000000
0.000000 0.000000 1.00000
counts[[1,1,2],[1,1,2]] += 1:
0.000000 0.000000 0.000000
0.000000 1.00000 0.000000
0.000000 0.000000 1.00000
counts[[1,1,2],[1,1,2]] += [1,1,1]:
0.000000 0.000000 0.000000
0.000000 1.00000 0.000000
0.000000 0.000000 1.00000
counts[[1,1,2],[1,1,2]] += [10,20,30]:
0.000000 0.000000 0.000000
0.000000 20.0000 0.000000
0.000000 0.000000 30.0000

It seems that ++ increments for each (x,y) pair as you expect. However, the +=
operation seems to be creating a set of result values by adding the set of
original values to the given scalar or vector, and then copying the results into
the array. In this way, when [1,1] is assigned values twice by this copying,
only the last value persists.

I seem to recall someone explaining this behaviour before, and thanks to
Russell, I realize one good way of getting *part* of what you (reasonably!) want
to do. If all of your 'e' values were equal, then you can find how many counts
of each (x,y) pair exist by using Hist_ND:
(http://tir.astro.utoledo.edu/idl/hist_nd.pro)

IDL> Print, Hist_ND(Transpose([[1,1,2],[1,1,2]]), 1, Min=0)
0 0 0
0 2 0
0 0 1

But, in general, to add a varying set of 'e' values to those (x,y) locations...
I have to think a bit...

Cheers,
-Dick

Dick Jackson Software Consulting
Victoria, BC, Canada
www.d-jackson.com

oliver wrote, On 2013-11-07, 4:45am:
> Hi
>
> This may be a much answered question, but searching for an answer has failed me.
>
> I have 3 (very large) arrays giving x values, y values and energy values.
>
> I wish to create two 2d arrays - one of total (summed) energy for a particular x,y value, and one of total counts per x,y value.
>
> An example of what I tried is below:
>
> x=[1,1,2]
> y=[1,1,2]
> e=[10,10,10]
>
> To create the 'counts' value, i used the following:
>
> counts=fltarr(5,5)
>
> counts(x,y)++
>
> This works. You end up with a value of 2 at position(1,1) and a value of 1 at position (2,2).
>
> I hoped to get the 'total energy' value by doing the following:
>
> totalenergy=fltarr(5,5)
>
> totalenergy(x,y)+=e
>
> However, this does not work. The final array only contains the last energy value added at each point.
>
> Is there an IDL trick I'm missing that allows you to incrementally add values to an array quickly?
>
> Thanks
>
> Oliver
>


--

Cheers,
-Dick

Dick Jackson Software Consulting
Victoria, BC, Canada
www.d-jackson.com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Non-blocking socket
Next Topic: strange !P.multi[0] behavior??

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

Current Time: Wed Oct 08 18:32:40 PDT 2025

Total time taken to generate the page: 0.00184 seconds