MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to reverse sign on the y's in a list of (x, y)'s?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61266] Re: How to reverse sign on the y's in a list of (x, y)'s?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 14 Oct 2005 05:54:05 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <dikt77$4tm$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

sherifffruitfly at gmail.com wrote:
> Hi all,
> 
> This is really dumb, but I just don't know how to do it...
> 
> Import from excel gives me a list of ordered pairs, and I want the 2nd
> element of each pair to be of opposite sign. Sticking the negative sign
> in front of the entire Import statement reverses both the 1st and the
> 2nd elements (duh). How do I get just the second item to reverse sign?
> 
> thanks!
> 
Hi,

One way of doing this is as follows. First we create some pairs of 
random machine-precision real numbers):

In[1]:=
data = Table[{Random[], Random[]}, {4}]

Out[1]=
{{0.519316,0.121246},{0.255378,0.733313},{
   0.477478,0.170173},{0.673604,0.86816}}

Then we instruct Mathematica to take _all_ the lines and the second 
column only of the matrix, change the sign and store the new values at 
the same place

In[2]:=
data[[All,2]] = -data[[All,2]]

Out[2]=
{-0.121246,-0.733313,-0.170173,-0.86816}

We can check that data as the required form

In[3]:=
data

Out[3]=
{{0.519316,-0.121246},{0.255378,-0.733313},{
   0.477478,-0.170173},{0.673604,-0.86816}}

Best regards,
/J.M.


  • Prev by Date: Re: big integer for Range
  • Next by Date: Re: big integer for Range
  • Previous by thread: Re: How to reverse sign on the y's in a list of (x, y)'s?
  • Next by thread: strange editor