[Date Index]
[Thread Index]
[Author Index]
Re: List handling
*To*: mathgroup at smc.vnet.net
*Subject*: [mg15284] Re: List handling
*From*: dreissBLOOP at bloop.earthlink.net (David Reiss)
*Date*: Thu, 31 Dec 1998 04:39:38 -0500
*Organization*: EarthLink Network, Inc.
*References*: <76ciqj$o51@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
In article <76ciqj$o51 at smc.vnet.net>, "Jorge Zickermann"
<jzickermann at mail.EUnet.pt> wrote:
> listA=
>
> {1977.06,1977.06,1977.06,1977.06,1977.06,2047.77,2047.77,2047.77,2047.77,218
> 1.55,2181.55,2181.55,2244.73,2244.73,2244.73,2305.5,2305.5,2305.5,2305.5,236
> 3.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92
> ,2363.92}
>
> ListB=
>
> {0.684807,0.683029,0.665242,0.665242,0.664123,0.683029,0.665242,0.665242,0.6
> 64123,0.640339,0.640339,0.620329,0.640339,0.640339,0.620329,0.661684,0.64033
> 9,0.640339,0.620329,0.640339,0.622044,0.640339,0.621506,0.660996,0.640339,0.
> 641006,0.640339,0.620935,0.640339,0.640339}
>
> ListC=
>
> {1971.45,1973.53,1994.29,1994.29,1995.6,2044.23,2065.,2065.,2066.3,2227.86,2
> 227.86,2251.22,2291.04,2291.04,2314.4,2326.89,2351.81,2351.81,2375.17,2410.2
> 2,2431.58,2410.22,2432.21,2386.11,2410.22,2409.44,2410.22,2432.88,2410.22,24
> 10.22}
>
> Position[ListB,_?(#>0.68&)]
>
> {{1},{2},{6}}
>
> Having obtained the positions of certain selected elements from ListB, I
> want to substitute the corresponding elements in ListA by the
> corresponding elements in ListC. In other words, I want to end up with;
>
>
> listA=
>
> {1971.45,1973.53,1977.06,1977.06,1977.06,2044.23,2047.77,2047.77,2047.77,218
> 1.55,2181.55,2181.55,2244.73,2244.73,2244.73,2305.5,2305.5,2305.5,2305.5,236
> 3.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92
> ,2363.92}
>
> Any help on how to do this is welcome. Thank you.
>
> Jorge
In[1]:=
ListA={1977.06,1977.06,1977.06,1977.06,1977.06,2047.77,
2047.77,2047.77,2047.77,2181.55,2181.55,2181.55,2244.73,
2244.73,2244.73,2305.5,2305.5,2305.5,2305.5,2363.92,2363.92,
2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92};
In[2]:=
ListB={0.684807,0.683029,0.665242,0.665242,0.664123,
0.683029,0.665242,0.665242,0.664123,0.640339,0.640339,
0.620329,0.640339,0.640339,0.620329,0.661684,0.640339,
0.640339,0.620329,0.640339,0.622044,0.640339,0.621506,
0.660996,0.640339,0. 641006,0.640339,0.620935,0.640339,0.640339};
In[3]:=
ListC={1971.45,1973.53,1994.29,1994.29,1995.6,2044.23,
2065.,2065.,2066.3,2227.86,2227.86,2251.22,2291.04,
2291.04,2314.4,2326.89,2351.81,2351.81,2375.17,2410.22,
2431.58,2410.22,2432.21,2386.11,2410.22,2409.44,2410.22,
2432.88,2410.22,2410.22};
In[4]:= pos=Position[ListB,_?(#>0.68&)]
Out[4]=
{{1},{2},{6}}
ReplacePart has a syntax that should do exactly what you want.
Unfortunately there is a bug in Mathematica 3 that prevents it from
evaluating according to expectations (it appears that this syntax was
not implemented as advertised, but it works in the upcoming version)
In[5]:= ReplacePart[ListA,ListC,pos,pos]
Out[5]=
{{1971.45,1973.53,1994.29,1994.29,1995.6,2044.23,2065.,2065.,2066.3,2227.86,
2227.86,2251.22,2291.04,2291.04,2314.4,2326.89,2351.81,2351.81,2375.17,
2410.22,2431.58,2410.22,2432.21,2386.11,2410.22,2409.44,2410.22,2432.88,
2410.22,2410.22}\[LeftDoubleBracket]{1},{2},{6}\[RightDoubleBracket],{
1971.45,1973.53,1994.29,1994.29,1995.6,2044.23,2065.,2065.,2066.3,
2227.86,2227.86,2251.22,2291.04,2291.04,2314.4,2326.89,2351.81,2351.81,
2375.17,2410.22,2431.58,2410.22,2432.21,2386.11,2410.22,2409.44,2410.22,
2432.88,2410.22,2410.22}\[LeftDoubleBracket]{1},{2},{6}
\[RightDoubleBracket],1977.06,1977.06,
1977.06,{1971.45,1973.53,1994.29,1994.29,1995.6,2044.23,2065.,2065.,2066.3,
2227.86,2227.86,2251.22,2291.04,2291.04,2314.4,2326.89,2351.81,2351.81,
2375.17,2410.22,2431.58,2410.22,2432.21,2386.11,2410.22,2409.44,2410.22,
2432.88,2410.22,2410.22}\[LeftDoubleBracket]{1},{2},{6}
\[RightDoubleBracket],2047.77,2047.77,2047.77,2181.55,2181.55,2181.55,
2244.73,2244.73,2244.73,2305.5,2305.5,2305.5,2305.5,2363.92,2363.92,2363.92,
2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92}
However, the following should do what you want
In[6]:=
testListA=ReplacePart[ListA, 0, pos]+(ListC-ReplacePart[ListC, 0, pos])
Out[6]=
{1971.45,1973.53,1977.06,1977.06,1977.06,2044.23,2047.77,2047.77,2047.77,
2181.55,2181.55,2181.55,2244.73,2244.73,2244.73,2305.5,2305.5,2305.5,2305.5,
2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,2363.92,
2363.92,2363.92}
These are the orignal elements of ListA
In[7]:= ListA[[Flatten[pos]]]
Out[7]=
{1977.06,1977.06,2047.77}
These are the elements of ListC that you are interested in placing in
ListA
In[8]:= ListC[[Flatten[pos]]]
Out[8]=
{1971.45,1973.53,2044.23}
And here they have been put into the new testListA
In[9]:= testListA[[Flatten[pos]]]
Out[9]=
{1971.45,1973.53,2044.23}
testListA only differs from ListA at the positions in question
In[10]:= testListA-ListA
Out[10]=
{-5.61,-3.53,0.,0.,0.,-3.54,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,
0.,0.,0.,0.,0.,0.,0.,0.}
Cheers,
David
--
David Reiss
dreissBLOOP at bloop.earthlink.net
To send personal email, remove the words "bloop" and "BLOOP" from the
email address
Prev by Date:
**Re: mathlink program hanging in MLAnswer**
Next by Date:
**Re: Contour Plotting on a sphere**
Previous by thread:
**Re: List handling**
Next by thread:
**Re: List handling**
| |