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

Home » Public Forums » archive » Re: replace elements in 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: replace elements in array [message #49001] Sat, 10 June 2006 12:16
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
johnadams_1980@yahoo.com writes:

> How do you replace certain (common) elements in a array without using a
> for loop? For e. g., I have an array:
>
> a=[45,67,9999.,9999.,24]
>
> and would like to replace all the 9999. with 0.00 so that a becomes
>
> [45,67,0.00,0.00,24]
>
> (the array is huge, so changing each element individually is not an
> option).

Like this:

indices = Where(a EQ 9999.0, count)
IF count GT 0 THEN a[indices] = 0.00

Be aware that floating point numbers cannot be represented,
always, exactly with a computer, so you often have to look
for a value plus or minus a small delta.

http://www.dfanning.com/math_tips/razoredge.html

I can't tell from your example if you have floats with 9999.0
thrown in there with long integers, or what. (Maybe you aren't
sure, but you should be. It could make a difference in how you
go about finding the values.)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Previous Topic: replace elements in array
Next Topic: Factory pressed dvd movies, ps2, psp, xbox backups for sale !!!

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

Current Time: Wed Oct 08 18:31:40 PDT 2025

Total time taken to generate the page: 0.00421 seconds