Re: replace elements in array [message #49001] |
Sat, 10 June 2006 12:16 |
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/
|
|
|