comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: row calculation in a 2D array
items: Re: row calculation in a 2D array

row calculation in a 2D array
type: item
description: 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
creator: Jonas
date: 1998-08-25T07:00:00-00:00

Re: row calculation in a 2D array
type: item
description: I don't know what the execution time penalty is for doing this, but I have often used avg=reform(rebin(A[3:6,*],1,10)) not sure if the reform is essential in this example but in general it is useful for making sure a vector is a one-D array. Dick French >> >> 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? >> >
creator: Richard G. French
date: 1998-08-31T07:00:00-00:00

Re: row calculation in a 2D array
type: item
description: "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>
creator: Vap User
date: 1998-08-31T07:00:00-00:00