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 #35170 is a reply to message #35165] Fri, 16 May 2003 15:19 Go to previous messageGo to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
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.
[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: Fri Oct 10 12:04:12 PDT 2025

Total time taken to generate the page: 1.20187 seconds