Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3174 > unrolled thread

Re: How to Do a Replacement with Two Conditions

Started byGregory Lypny <gregory.lypny@videotron.ca>
First post2011-06-18 21:44 +0000
Last post2011-06-18 21:44 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to Do a Replacement with Two Conditions Gregory Lypny <gregory.lypny@videotron.ca> - 2011-06-18 21:44 +0000

#3174 — Re: How to Do a Replacement with Two Conditions

FromGregory Lypny <gregory.lypny@videotron.ca>
Date2011-06-18 21:44 +0000
SubjectRe: How to Do a Replacement with Two Conditions
Message-ID<itj682$k3u$1@smc.vnet.net>
Hi Murray,

Good stuff!  I should have thought of Boole.  I'm surprised too that 
Greater is not listable.

Thanks,

Gregory


On Fri, Jun 17, 2011, at 9:48 AM, Murray Eisenberg wrote:

> I was with you until you said "to create a dummy variable". If you 
just want to replace numbers > 180 with 1 and those <= 180 with 0, 
then Boole will do the trick:
>
>   myList = Append[RandomInteger[{0, 360}, 10], 180]
> {235, 189, 23, 169, 229, 93, 14, 284, 251, 290, 180}
>
>   Boole[ Thread[myList > 180] ]
> {1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0}
>
> The Thread is needed because > (Greater) is not Listable -- somewhat 
surprisingly to me.
>
>
> On 6/17/2011 12:07 AM, Gregory Lypny wrote:
>> Hello everyone,
>>
>> I have a list of integers and I want to replace numbers bigger than 
180 with one and those less than or equal to 180 with 0 to create a 
dummy variable.  The ones are easy:
>>
>> 	myList /. x_ /; x>  180 ->  1
>>
>> How do I get the zeros in there?
>>
>> Regards,
>>
>> Gregory
>>
>
> --
> Murray Eisenberg                     murray@math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower      phone 413 549-1020 (H)
> University of Massachusetts                413 545-2859 (W)
> 710 North Pleasant Street            fax   413 545-1801
> Amherst, MA 01003-9305

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web