       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:= list
Out= {{a,-1},{b,-2},{c,-3}}

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

Summary:

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

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

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

Out= {-1,-2,-3}

In:= list

Out= {{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?