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

Home » Public Forums » archive » Re: 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 #12597 is a reply to message #12591] Tue, 25 August 1998 00:00 Go to previous messageGo to previous message
Kevin Ivory is currently offline  Kevin Ivory
Messages: 71
Registered: January 1997
Member
Jonas wrote:
> 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?

A general anwser is not easy, but your example is. You need routines
that only work on certain dimensions of multidimensional matrices.
For calculating the mean I have exactly what you need: It is a one-liner
(with a few comments) named 'average'. Here is an example:

IDL> ten_2d = bindgen(10,10)
IDL> print, average(ten_2d(4:7,*), 1)
5.50000 15.5000 25.5000 35.5000 45.5000 55.5000
65.5000 75.5000 85.5000 95.5000

Hope this helps,
Kevin
--
Kevin Ivory Tel: +49 5556 979 434
Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240
Max-Planck-Str. 2 mailto:Kevin.Ivory@linmpi.mpg.de
D-37191 Katlenburg-Lindau, GERMANY http://www.gwdg.de/~kivory2/

------------------------------------------------------------ ------------------

; Time-stamp: <average.pro Thu Apr 3 16:00:48 MET DST 1997>

function average, array, dim, _extra=_extra
;+
; calculates the average value of an array (all arguments as in 'total')
; arguments
; array array to be averaged, any type except string
; dim dimension over which to average (see 'total' documentation)
; keywords
; _extra all keywords passed to 'total'
;-
if n_elements(dim) eq 0 then dim = 0
return, total(array, dim, _extra=_extra) / (total(finite(array), dim)>1)
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: What is going on with the minor ticks on log plots?????
Next Topic: Boundary Chain Code

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

Current Time: Wed Oct 15 13:47:37 PDT 2025

Total time taken to generate the page: 1.12126 seconds