2

I have two lists.

a = {{2, 2}, {3, 3}, {4, 4}, {5, 5}};
b = {1, 1};

I want to subtract a from b and want to get

{{1, 1}, {2, 2}, {3, 3}, {4, 4}}`

When I tried Subtract[a, b], I got an error. How do I fix this?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user2987529
  • 145
  • 5

1 Answers1

4

Artes comment as an answer.

a = {{2, 2}, {3, 3}, {4, 4}, {5, 5}};
b = {1, 1};
(# - b)& /@ a
{{1, 1}, {2, 2}, {3, 3}, {4, 4}}

In the special case of your example, because of the way Mathematica defines addition of a scalar to a list, you can do

a - 1
{{1, 1}, {2, 2}, {3, 3}, {4, 4}}

a - x will work for any pair of the form b = {x, x}.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257