Re: normalize a table
- To: mathgroup at smc.vnet.net
- Subject: [mg72790] Re: [mg72768] normalize a table
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 20 Jan 2007 02:36:29 -0500 (EST)
- Reply-to: hanlonr at cox.net
data={{1,0.2},{2,0.3},{3,0.4},{4,0.5}}; #/{Max[data[[All,1]]],1}&/@data {{1/4, 0.2}, {1/2, 0.3}, {3/4, 0.4}, {1, 0.5}} A different normalization (first terms sum to unity): #/{Total[data[[All,1]]],1}&/@data {{1/10, 0.2}, {1/5, 0.3}, {3/10, 0.4}, {2/5, 0.5}} Bob Hanlon ---- Ruth <ruth.lazkoz at ehu.es> wrote: > Hi, > > I want to do something really simple, which is take a table made of > pairs and normalize the first number in each pair by dividing by the > largest. > > For instance, I want to transform this list > > {{1,0.2},{2,0.3},{3,0.4},{4,0.5}} > > into this one > > {{1/4, 0.2}, {1/2, 0.3}, {3/4, 0.4}, {1, 0.5}} > > The way i did it is through the chain of commands > > firsttable={{1,0.2},{2,0.3},{3,0.4},{4,0.5}}; > > > top=Max[Table[firsttable[[i,1]],{i,1,Length[firsttable]}]]; > > > mytable=Do[newtable=ReplacePart[newtable,newtable[[i,1]]/top,{i, > 1}],{i,1,Length[firsttable]}] > > There must be a more elegant way to do it, but @&# and commands like > those are still hard to handle for me, and I could not work it out > > Thanks in advance, > > Ruth