Re: Adding elements in an Array [message #85968 is a reply to message #85967] |
Sun, 22 September 2013 11:46   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
bhattacharjee12@gmail.com writes:
>
> Hi,
> I am new to IDl. I was hoping if you guys can help with my problem.
> I will explain my problem with an example.
> Lets say I have an array
> x=[1,2,3,4,5,6,1,2,3]
> & I want to average lets say every 3 elements and put the results in a new array say y
> Where y would look like
> y=[2,5,2]
> Is there a nifty IDL function/easy way which would do that?
IDL> x=[1,2,3,4,5,6,1,2,3]
IDL> x = reform(x, 3, 3)
IDL> b = Mean(x, dimension=1)
IDL> print, b
2.00000 5.00000 2.00000
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|