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

Home » Public Forums » archive » Re: Sum of elements in an 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: Sum of elements in an array [message #2305] Thu, 09 June 1994 12:06 Go to previous message
velt is currently offline  velt
Messages: 19
Registered: June 1994
Junior Member
In article ftb@due.uninett.no, ragnar@kvark.fi.uib.no (Ragnar Aas) writes:
> I'm working on a project where I need to sum the result of many IF-statements.
> In order to make this operation faster, I want to vectorize it. The way I
> want it is :
>
> sum=(array_1.element EQ 1)
>
> with sum a scalar, and array_1 an array. (BIG surprise!)
> In other words : If array_1.element equals 1, then add 1 to sum.
> How do I go about to solve this?
>
> Thanx in advance.
>
> Ragnar Aas

Try:

sum=n_elements(where(array_1.element EQ 1))

Or, when the values of element can only be 0 or 1:

sum=total(array_1.element)

Good Luck.

Robert Velthuizen
Dept of Radiology
University of South Florida.
[Message index]
 
Read Message
Read Message
Previous Topic: How to I get IDL postscript files from Sun to Mac?
Next Topic: How to contact Visual Numerics?

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

Current Time: Fri Oct 10 06:43:59 PDT 2025

Total time taken to generate the page: 1.04147 seconds