Skip to main content
added 249 characters in body
Source Link
bmf
  • 17k
  • 2
  • 32
  • 68

I am glad to see that people are using Threaded

I am surprised nobody mentioned the use of Inner

Grabbing the list from @eldo

list = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};

This

Inner[Times, list, {1, -1}, List]

returns

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

We can, also, use Splice

Cases[list, x_ :> {First@x, Splice@Rest@-x}]

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

And ApplyTo

list = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};
list //= ReplaceAt[x_ :> -x, {All, 2}];
list

giving

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

I am glad to see that people are using Threaded

I am surprised nobody mentioned the use of Inner

Grabbing the list from @eldo

list = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};

This

Inner[Times, list, {1, -1}, List]

returns

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

We can, also, use Splice

Cases[list, x_ :> {First@x, Splice@Rest@-x}]

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

I am glad to see that people are using Threaded

I am surprised nobody mentioned the use of Inner

Grabbing the list from @eldo

list = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};

This

Inner[Times, list, {1, -1}, List]

returns

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

We can, also, use Splice

Cases[list, x_ :> {First@x, Splice@Rest@-x}]

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

And ApplyTo

list = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};
list //= ReplaceAt[x_ :> -x, {All, 2}];
list

giving

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

Source Link
bmf
  • 17k
  • 2
  • 32
  • 68

I am glad to see that people are using Threaded

I am surprised nobody mentioned the use of Inner

Grabbing the list from @eldo

list = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};

This

Inner[Times, list, {1, -1}, List]

returns

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}

We can, also, use Splice

Cases[list, x_ :> {First@x, Splice@Rest@-x}]

{{x1, -y1}, {x2, -y2}, {x3, -y3}, {x4, -y4}}