Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: normalize a table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72809] Re: normalize a table
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Sat, 20 Jan 2007 03:52:51 -0500 (EST)

On 1/19/07 at 1:01 AM, ruth.lazkoz at ehu.es (Ruth) wrote:

>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

First, getting the divisor can be done as

In[2]:=
data={{1,0.2},{2,0.3},{3,0.4},{4,0.5}};

In[3]:=
scale=Max[First/@data]

Out[3]=
4

then, the desired result can be achieved with pattern matching as:

In[4]:=
data/.{a_,b_}->{a/scale,b}

Out[4]=
{{1/4, 0.2}, {1/2, 0.3}, {3/4, 0.4}, {1, 0.5}}

or functional programming as

In[5]:=
{First@#/scale,Last@#}&/@data

Out[5]=
{{1/4, 0.2}, {1/2, 0.3}, {3/4, 0.4}, {1, 0.5}}
--
To reply via email subtract one hundred and four


  • Prev by Date: how to quickly read a >10MB big file
  • Next by Date: Help with plotting and iterations
  • Previous by thread: Re: normalize a table
  • Next by thread: Re: normalize a table