Re: Using 'IF' function on 'Lists' in Mathematica 6.01
- To: mathgroup at smc.vnet.net
- Subject: [mg85045] Re: [mg85035] Using 'IF' function on 'Lists' in Mathematica 6.01
- From: Carl Woll <carlw at wolfram.com>
- Date: Fri, 25 Jan 2008 05:04:06 -0500 (EST)
- References: <200801240950.EAA15143@smc.vnet.net>
Lea Rebanks wrote:
>Dear All,
>
>I trying to Use the 'IF' function on a 'List' - 'data' below.
>
>I am trying to get the output as a 'List' of 1's & 0's
>
>
Lookup Unitize:
In[33]:= Unitize[data]
Out[33]=
{1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,\
0,1,1,1,1,1,0}
Carl Woll
Wolfram Research
>In[7]:= data = {0.25, 0.292893219, 0.5,
> 0.707106781, 0.75, 0, 0.25,
> 0.292893219, 0.5, 0.707106781,
> 0.75, 0, 0.25,
> 0.2928932190000002, 0.5,
> 0.7071067809999998, 0.75, 0,
> 0.25, 0.2928932190000002, 0.5,
> 0.7071067809999998, 0.75, 0, 0.5,
> 0.5857864380000004, 1,
> 1.4142135619999996, 1.5, 0, 0.5,
> 0.5857864380000004, 1,
> 1.4142135619999996, 1.5, 0, 0.5,
> 0.5857864379999995, 1,
> 1.4142135620000005, 1.5, 0, 0.5,
> 0.5857864399999997, 1,
> 1.4142135600000003, 1.5, 0, 0.75,
> 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0}
>
>
>In[8]:= Clear[testIf]
>testIf[dataValue_] :=
> If[dataValue == 0, 0, 1]
>
>In[11]:= testIf[data[[11]]]
>Out[11]= 1
>
>In[13]:= testIf[data[[12]]]
>Out[13]= 0
>
>These two above values are working fine, however I want to produce a 'List'.
>
>In[12]:= testIf[data[[All]]]
>Out[12]= If[{0.25, 0.292893219, 0.5,
> 0.707106781, 0.75, 0, 0.25,
> 0.292893219, 0.5, 0.707106781,
> 0.75, 0, 0.25,
> 0.2928932190000002, 0.5,
> 0.7071067809999998, 0.75, 0,
> 0.25, 0.2928932190000002, 0.5,
> 0.7071067809999998, 0.75, 0,
> 0.5, 0.5857864380000004, 1,
> 1.4142135619999996, 1.5, 0, 0.5,
> 0.5857864380000004, 1,
> 1.4142135619999996, 1.5, 0, 0.5,
> 0.5857864379999995, 1,
> 1.4142135620000005, 1.5, 0, 0.5,
> 0.5857864399999997, 1,
> 1.4142135600000003, 1.5, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0,
> 0.75, 0.8786796599999995, 1.5,
> 2.1213203400000005, 2.25, 0} ==
> 0, 0, 1]
>
>Any help or advice gratefully received.
>
>Best Regards - Lea Rebanks...
>
>
>
>
- References:
- Using 'IF' function on 'Lists' in Mathematica 6.01
- From: "Lea Rebanks" <lrebanks@netvigator.com>
- Using 'IF' function on 'Lists' in Mathematica 6.01