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

Home » Public Forums » archive » Re: replace array's elemets
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 array's elemets [message #35176 is a reply to message #35171] Fri, 16 May 2003 12:04 Go to previous messageGo to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
"Roberto" <graftons@tiscalinet.it> wrote in message
news:4ac6b3e5.0305160733.50173373@posting.google.com...
> I have a 100x100 array.
> How can I replace an element if is different from 0?
> I would replace all elements different from 0 with 1.
> thank and sorry for the trouble.

IDL> a = [0, 1, 2, 3, 0, 5, 6, 7, 0, 9]
IDL> a[*] = a ne 0
IDL> print, a, format='(10i4)'
0 1 1 1 0 1 1 1 0 1

If your array contains floating point values, you should use something like

IDL> a = [0.0, 1, 2, 3, 0, 5, 6, 7, 0, 9]
IDL> info = machar()
IDL> value = 0.0
IDL> a[*] = abs(a - value) gt info.eps
IDL> print, a, format='(10f4.1)'
0.0 1.0 1.0 1.0 0.0 1.0 1.0 1.0 0.0 1.0

Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: plotting from high values to low values
Next Topic: read pixels

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

Current Time: Wed Oct 08 17:43:27 PDT 2025

Total time taken to generate the page: 0.00400 seconds