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

Home » Public Forums » archive » row calculation in a 2D array
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: row calculation in a 2D array [message #12703 is a reply to message #12604] Mon, 31 August 1998 00:00 Go to previous message
Vap User is currently offline  Vap User
Messages: 31
Registered: April 1998
Member
"Jonas" <jonas_2@hotmail.com> writes:


The general case may be hard, if not impossible. Depends on what you
mean by 'operation' below. To do it generally probably requires that
the operation be a linear combination of the elements of the
arrays. Anyway, this will work to find the average.

if A is your 10 by 10 array.

tmpA=A[3:6,*] ; the sub-array

avg=replicate( 1, 4)##transpose(tmpA)/4.; the average.

or, equivalently, but transposed,

avg = transpose(replicate(1,4))#tmpA/4.


You should almost always be able to replace loops of summations with the
'#' (or '##') operator and a judicicious choice of multiplicand.

whd


>
> Probably a damn simple one, but anyway:
>
> I want to perform the same operation on each sub-row in a 2D array.
> Say I want to calculate the mean of element 4-7 in each row of a 10x10
> array, and store the result in a 10 element-vector, where each element holds
> the mean from the respective row
>
> how is this done the smartest way, without using time-consuming loops?
>
> sincerely
> Jonas
>
>

--
I don't speak for JPL, it doesn't speak for me.
Well, not all the time, at least.
William Daffer <vapuser@haifung.jpl.nasa.gov>
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: how to find number of lines in an ASCII file?
Next Topic: Re: Variable Tick Scaling

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

Current Time: Sat Oct 11 17:19:04 PDT 2025

Total time taken to generate the page: 0.00947 seconds