0
$\begingroup$

I have have some (x,y) lists generated by:

Do[Spec[2*i] = AllData[[All, (2*i + 1) ;; (2*i + 2)]], {i, 0, 10}];

So that Spec[0], Spec[2] ... Spec[20] are (x,y) values from a larger table. I want to normalize the y values for each Spec[i] so that they go from 0 to 1. How can I do that?

$\endgroup$

2 Answers 2

2
$\begingroup$
mylist = Table[{RandomReal[], RandomReal[{5, 6}]}, 10];

mynewlist = {#[[1]], (#[[2]] - Min[mylist[[All, 2]]])/(Max[mylist[[All, 2]]] - 
       Min[mylist[[All, 2]]])} & /@ mylist

or shorter:

Transpose[{(a = Transpose[mylist])[[1]], Rescale[a[[2]]]}]

or if this were code golf:

t = Transpose; t[{(a = t[mylist])[[1]], Rescale[a[[2]]]}]
$\endgroup$
0
$\begingroup$

Well, I don't know if this is exactly what you want: (since you haven't provided me AllData)

Say I generate a number of Spec lists of two variables:

    Spec[j_] = Table[Partition[RandomSample[Range[40], 20], 2], {i, 1, 10}][[j]] // Quiet;

and any element say,

    Spec[1]
    (*{{2, 1}, {24, 14}, {17, 28}, {34, 20}, {29, 5}, {8, 15}, {12,  39}, {21, 6}, {10, 35}, {22, 4}}*)

Now, I want to normalize all y's to 0,1 and Thread them together. So, I get, say, Newspec:

   NewSpec[i_] := Thread[{Spec[i][[All, 1]], Normalize[Spec[i][[All, 2]]]}] // N

Your new list with normalized y values is:

    NewSpec[1]
    (*{{2., 0.0150261}, {24., 0.210366}, {17., 0.420732}, {34.,  0.300523}, {29., 0.0751307}, {8., 0.225392}, {12., 0.586019}, {21.,  0.0901568}, {10., 0.525915}, {22., 0.0601045}}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.