I've got the following:

list = {{{x11, y11}, {x12, y12}}, {{x21, y21}, {x22, y22}}}


The first element is a list of x/y data points. I want to divide each element of this list by the first element in the list. Then I want to do the same for the second list (and etc., for longer lists). This works:

Table[#/First[list[[i]]] & /@ list[[i]], {i, Length[list]}]


Shouldn't I be able to use Thread or MapThread or something, in order to clean this up? (So I don't have to refer to list three times?)

I'm not smart enough to do it. Thanks for any help.

ReplacePart can specify the operation directly:

ReplacePart[list, {i_, j_} :> list[[i, j]] / list[[i, 1]]]


The MapIndexed equivalent is a little shorter, but perhaps also a little less readable:

MapIndexed[# / list[[#2[[1]], 1]] &, list, {2}]


I think this is cleaner:

 twoListsOfPairs = {{{x11, y11}, {x12, y12}, {x13, y13}}, {{x21, y21}, {x22, y22}, {x23, y23}}};

normalizeToFirst[list_] := Transpose[Transpose[list]/First[list]]

normalizeToFirst /@ twoListsOfPairs


which returns:

 {{{1, 1}, {x12/x11, y12/y11}, {x13/x11, y13/y11}}, {{1, 1}, {x22/x21, y22/y21}, {x23/x21, y23/y21}}}


Instead of threading, I believe you can use patterns which is much cleaner

Replace[list, {i_, j_} -> {{1, 1}, j/i}, 1]

• This is awesome, but I'm not as familiar with patterns. Mar 27, 2018 at 18:06