# add columns of list {a0,b0} to columns of list {{a0,b0} ,{a1,b1} ,{a2,b2} ...{ax,bx} } [closed]

If I want to add the columns of {1,2} to each of the columns of say

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

resulting in

{{2, 4}, {4, 4}, {5, 4}}


How would I do this? and for any given number of rows?

{{1,2},{3,2}...{x,y}}

Every time anyone says "I want to do x to every item in a list" think Map

m={{1,2},{3,2},{4,2}};
Map[#+{1,2}&,m]


which returns

{{2,4},{4,4},{5,4}}


If that # and & stuff is too confusing then you can do the same by writing your own function

m={{1,2},{3,2},{4,2}};
f[v_]:=v+{1,2};
Map[f,m]


which returns

{{2,4},{4,4},{5,4}}


Another way.

pts = {{1, 2}, {3, 2}, {4, 2}};
TranslationTransform[First@pts] /@ pts

pts = {{1, 2}, {3, 2}, {4, 2}};
ConstantArray[{1, 0, 0}, Length@pts] . pts + pts


{{2, 4}, {4, 4}, {5, 4}}

Two (of probably very many) ways:

data//With[{x = #[]},ArrayReduce[x+#&,#,2]]&

(* {{2, 4}, {4, 4}, {5, 4}} *)


or

data//With[{x = #[]},x+#&/@#]&


where

data ={{1,2},{3,2},{4,2}}


Edit

Add a column to all columns (see this answer by Carl Woll)

addColToAll[mat_,col_] := With[{x=col},mat.SparseArray[{{x,x}->2,Band[{1, 1}]->1,
{x,_}->1},Dimensions[mat][]]]


Add a row to all rows:

addRowToAll[mat_,row_] := With[{x=row},Transpose[mat].SparseArray[{{x,x}->2,Band[{1, 1}]->1,{x,_}->1},Dimensions[mat][]]//Transpose]


Examples

addRowToAll[data,1]
(* {{2, 4}, {4, 4}, {5, 4}} *)