Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg61278] Re: How to reverse sign on the y's in a list of (x, y)'s?
  • From: "Bill White" <minutiae at gmail.com>
  • Date: Fri, 14 Oct 2005 05:54:39 -0400 (EDT)
  • References: <dikt77$4tm$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here's a simple-minded approach (to help me learn about lists :-).
First, a simple list:

list = {{a, 1}, {b, 2}, {c, 3}}

Note that we can grab the elements in question with this:

list[[All, 2]]

We can make them negative by Map'ing Minus over them:

Minus /@ list[[All, 2]]

And the Help Browser says, "You can always reset one or more pieces of
a list by doing an assignment like m[[ \[Ellipsis] ]] = value."

So we should be able to change the sign of the 2nd elements with this:

list[[All, 2]] = Minus /@ list[[All, 2]]

Indeed, here is the new list:

In[18]:= list
Out[18]= {{a,-1},{b,-2},{c,-3}}

--------------------------------------

Summary:

In[19]:= list={{a,1},{b,2},{c,3}}

Out[19]= {{a,1},{b,2},{c,3}}

In[20]:= list[[All,2]]=Minus/@list[[All,2]]

Out[20]= {-1,-2,-3}

In[21]:= list

Out[21]= {{a,-1},{b,-2},{c,-3}}

Cheers


  • Prev by Date: Re: TagSet and the listability of Plus[ ]
  • Next by Date: Re: Re: Re: Language vs. Library
  • Previous by thread: Re: How to reverse sign on the y's in a list of (x, y)'s?
  • Next by thread: Re: How to reverse sign on the y's in a list of (x, y)'s?