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 #35165 is a reply to message #35158] Sat, 17 May 2003 04:13 Go to previous messageGo to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
James Kuyper wrote:

> Reimar Bauer wrote:
>>
>> Roberto wrote:
>>
>>> Hi
>>> 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.
>>> Roberto
>>
>> Dear Roberto
>>
>> I suggest something like this
>>
>> example data:
>> x=indgen(100,100)
>>
>> result:
>> result=x<1
>
> That doesn't do the right thing with negative numbers. "result=x ne 0"
> is the right choice. More generally,
>
> x[where(x ne 0)] = 1
>
> has the advantage of being more easily generalized to the case of more
> complicated search conditions, and different replacement values.
> However, it will produce an error message if no replacements are needed.


and what did you say to this:

print,(abs(x)<1)

I often use myself "where" :-)

regards
Reimar


--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
[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:44:31 PDT 2025

Total time taken to generate the page: 0.00422 seconds