Message Boards Message Boards

Manipulating Linear Tables with Multiple External Intervals and Quantities

This topic is just about some examples of table manipulation. There are several types of operations that can be done. If anyone wants to add some types is very welcome to post here. This is a simple example of a linear table with internal range and made with a certain amount of repetitions:

Flatten[Table[Table[n1, {n1, 11, 19}], 3]]

enter image description here

Below is an example of a table with only one interval and quantity control, both external to the command, as well as some manipulations such as: organization, order, quantity numbers of each type, random permutation, and random choice.

  • Table manipulation with external interval and quantity controlled.

    interval = {11, 19};  (*= interval of numbers *)
    quantity = 3;   (*= quantity of each number *)
    
    r = RandomSample[
       rx = Flatten[
         Table[Table[
           i, {i, FromDigits[Drop[interval, -1]], 
            FromDigits[Drop[interval, 1]]}], quantity]]];
    rx
    Flatten[Gather[rx]]
    Sort[rx, Greater]
    Counts[rx]
    r 
    {{{RandomChoice[r]}}, N[100*quantity/Count[r, _], 4]}
    
    (* Out[1]= raw table *)
    (* Out[2]= table with gathered elements *)
    (* Out[3]= sorted table in reverse order *)
    (* Out[4]= quantity of each number *)
    (* Out[5]= random permutation *)
    (* Out[6]= {random pick, % probability} *)
    

enter image description here

Now a similar type of table but with multiple ranges outside the command and only one quantity control:

  • Table manipulation with multiple external intervals and quantity controlled.

    intervals = {{7, 9}, {2, 5}, {19, 20}, {15, 
        17}};  (*= multiple intervals *)
    quantities = 2;   (*= quantity of each number *)
    
    r2 = RandomSample[
      r1 = Flatten[
        Table[Table[
          Table[a, {a, 
            FromDigits[Drop[FromDigits[Take[intervals, {b}]], -1]], 
            FromDigits[Drop[FromDigits[Take[intervals, {b}]], 1]]}], {b, 
           1, Count[intervals, _]}], quantities]]];
    r1
    Flatten[Gather[r1]]
    Sort[r1]
    Counts[r1]
    r2
    {{{RandomChoice[r2]}}, N[100*quantities/Count[r2, _], 4]}
    
    (* Out[1]= raw table *)
    (* Out[2]= table with gathered elements *)
    (* Out[3]= sorted table *)
    (* Out[4]= quantity of each number *)
    (* Out[5]= random permutation *)
    (* Out[6]= {random pick, % probability} *)
    

enter image description here

ListPlot[r1]   (* before random permutation *)
ListPlot[r2]   (* after random permutation *)

enter image description here

Below is another type of table, but with multiple external intervals and quantities of each interval controlled separately as well as some other variations of manipulations:

  • Table manipulation with multiple external intervals and multiple quantities controlled.

    intervals2 = {{5, 7}, {35, 36}, {2, 3}, {51, 54}, {15, 
        17}};   (*= multiple intervals *)
    quantities2 = {3, 4, 2, 1, 
      3};   (*= quantity of each number for each interval *)
    
    r22 = RandomSample[
      r21 = Flatten[
        Table[Table[
          Table[l, {l, 
            FromDigits[Drop[FromDigits[Take[intervals2, {m}]], -1]], 
            FromDigits[Drop[FromDigits[Take[intervals2, {m}]], 1]]}], 
          FromDigits[Take[quantities2, {m}]]], {m, 1, 
          Count[quantities2, _]}]]];
    r21
    Flatten[Gather[r21]]
    AlphabeticSort[IntegerName[r21]]
    Counts[r21]
    r22
    z = RandomChoice[r22];
    {{{z}}, N[Count[r21, BlockRandom[z]]*100/Count[r21, _], 4]}
    
    (* Out[1]= raw table *)
    (* Out[2]= table with gathered elements *)
    (* Out[3]= sorted table by alphabetic order *)
    (* Out[4]= quantity of each number *)
    (* Out[5]= random permutation *)
    (* Out[6]= {random pick, % probability} *)
    

enter image description here

ListPlot[r21]  (* before random permutation *)
ListPlot[r22]  (* after random permutation *)

enter image description here

These are just a few examples, the ones I know, and if there are other ways or types of manipulation I'd love to know. That topic is about that.

Thanks.

POSTED BY: Claudio Chaib
3 Replies

Finally, the manipulation can be done automatically with the number of intervals and doing with quantity control for each interval defined outside the command.

intervals = {{1, 3}, {5, 7}, {9, 11}, {13, 15}};
quantities = {1, 2, 3, 4};

Manipulate[
 ListPlot[Flatten[
   Table[Flatten[
     Table[j, {j, 
       FromDigits[
        Take[FromDigits[Take[intervals, {nintervals}]], {1}]], 
       FromDigits[
        Take[FromDigits[Take[intervals, {nintervals}]], {2}]]}, 
      FromDigits[Take[quantities, {nintervals}]]]], {nintervals, 1, 
     nintervals}]]], {nintervals, 1, Count[quantities, _]}]

enter image description here

And we can also define which intervals can participate in the manipulation and control them independently.

inter = {{4, 6}, {8, 10}, {12, 14}};
na = 20; nb = 20; nc = 20;

Manipulate[
 ListPlot[Flatten[{Table[
     Table[i, {i, FromDigits[Take[FromDigits[Take[inter, {1}]], {1}]],
        FromDigits[Take[FromDigits[Take[inter, {1}]], {2}]]}, a], aa],
     Table[Table[
      j, {j, FromDigits[Take[FromDigits[Take[inter, {2}]], {1}]], 
       FromDigits[Take[FromDigits[Take[inter, {2}]], {2}]]}, b], bb], 
    Table[Table[
      k, {k, FromDigits[Take[FromDigits[Take[inter, {3}]], {1}]], 
       FromDigits[Take[FromDigits[Take[inter, {3}]], {2}]]}, c], 
     cc]}]], {a, 1, na}, {b, 1, nb}, {c, 1, 
  nc}, {aa, {0, 1}}, {bb, {0, 1}}, {cc, {0, 1}}]
Manipulate[
 ListPlot[RandomSample[
   Flatten[{Table[
      Table[i, {i, 
        FromDigits[Take[FromDigits[Take[inter, {1}]], {1}]], 
        FromDigits[Take[FromDigits[Take[inter, {1}]], {2}]]}, a], aa],
      Table[Table[
       j, {j, FromDigits[Take[FromDigits[Take[inter, {2}]], {1}]], 
        FromDigits[Take[FromDigits[Take[inter, {2}]], {2}]]}, b], bb],
      Table[Table[
       k, {k, FromDigits[Take[FromDigits[Take[inter, {3}]], {1}]], 
        FromDigits[Take[FromDigits[Take[inter, {3}]], {2}]]}, c], 
      cc]}]]], {a, 1, na}, {b, 1, nb}, {c, 1, 
  nc}, {aa, {0, 1}}, {bb, {0, 1}}, {cc, {0, 1}}]

enter image description here

For now these are my results from this work. Thanks.

POSTED BY: Claudio Chaib

Now doing the manipulations. First with an external range to the command and the quantity being controlled. Note: to change the result of random permutation just change the seed number.

intervalk = {11, 19}; 
quantityk = 3; 
seed = 124;

r = {SeedRandom[seed]; 
   BlockRandom[
    RandomSample[
     rx = Flatten[
       Table[Table[
         ii2, {ii2, FromDigits[Drop[intervalk, -1]], 
          FromDigits[Drop[intervalk, 1]]}], quantityk]]]]};
rx
r

enter image description here

Manipulate[
 ListPlot[Flatten[
   Table[Table[
     ii2, {ii2, FromDigits[Drop[intervalk, -1]], 
      intervals}], {quantity}]]], {quantity, 1, 
  quantityk}, {intervals, FromDigits[Drop[intervalk, -1]], 
  FromDigits[Drop[intervalk, 1]]}]

enter image description here

Manipulate[
 ListPlot[BlockRandom[
   RandomSample[
    Flatten[Table[
      Table[ii2, {ii2, FromDigits[Drop[intervalk, -1]], 
        FromDigits[
         Drop[intervalk, 1]]}], {quantity2}]]]]], {quantity2, 1, 
  quantityk}]
Do[Print[BlockRandom[
   RandomSample[
    Flatten[Table[
      Table[ii2, {ii2, FromDigits[Drop[intervalk, -1]], 
        FromDigits[Drop[intervalk, 1]]}], {g}]]]]], {g, 1, quantityk}]

enter image description here

Then with multiple intervals outside the table and with the quantity of repetitions controlled. Again to have new random values in the permutation just change the number of the seed.

intervalsk = {{7, 9}, {2, 5}, {19, 20}, {15, 17}};    
quantitiesk = 2;   
seed = 124;

r2 = {SeedRandom[seed]; 
   BlockRandom[
    RandomSample[
     r1 = Flatten[
       Table[Table[
         Table[a2, {a2, 
           FromDigits[Drop[FromDigits[Take[intervalsk, {b}]], -1]], 
           FromDigits[
            Drop[FromDigits[Take[intervalsk, {b}]], 1]]}], {b, 1, 
          Count[intervalsk, _]}], quantitiesk]]]]};
r1
r2

enter image description here

Manipulate[
 ListPlot[Flatten[
   Table[Table[
     Table[a2, {a2, 
       FromDigits[
        Drop[FromDigits[Take[intervalsk, {intervals}]], -1]], 
       FromDigits[
        Drop[FromDigits[Take[intervalsk, {intervals}]], 
         1]]}], {intervals, 1, intervals}], quantities]]], {intervals,
   1, Count[intervalsk, _]}, {quantities, 1, quantitiesk}]

enter image description here

Manipulate[
 ListPlot[BlockRandom[
   RandomSample[
    Flatten[Table[
      Table[Table[
        a2, {a2, 
         FromDigits[
          Drop[FromDigits[Take[intervalsk, {intervals2}]], -1]], 
         FromDigits[
          Drop[FromDigits[Take[intervalsk, {intervals2}]], 
           1]]}], {intervals2, 1, intervals2}], 
      quantities2]]]]], {intervals2, 1, 
  Count[intervalsk, _]}, {quantities2, 1, quantitiesk}]
Do[Print[BlockRandom[
   RandomSample[
    r1 = Flatten[
      Table[Table[
        Table[a2, {a2, 
          FromDigits[Drop[FromDigits[Take[intervalsk, {b}]], -1]], 
          FromDigits[
           Drop[FromDigits[Take[intervalsk, {b}]], 1]]}], {b, 1, b}], 
       quantities2]]]]], {quantities2, 1, quantitiesk}, {b, 1, 
  Count[intervalsk, _]}]

enter image description here

That's it for now... Thank you.

POSTED BY: Claudio Chaib

Thinking of ways to do more or less complex interpolations and multiple interpolations at the same time can be this way using the Table command:

x = {{1, 2, 12}, {2, 4, 24}, {3, 8, 38}, {4, 16, 416}, {5, 32, 532}};
y = {{3, 6, 36}, {5, 10, 510}, {7, 14, 714}, {9, 18, 918}, {11, 22, 
    1122}};
z = {{5, 10, 15}, {10, 15, 20}, {15, 20, 25}, {20, 25, 30}, {25, 30, 
    35}};

h1 = Table[{FromDigits[Take[FromDigits[Take[x, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[y, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {1}]]}, {m, 1, 
   Count[x, _]}]
(* get {x11,y11,z11},{x21,y21,z21}... *)

h2 = Table[{FromDigits[Take[FromDigits[Take[x, {m}]], {2}]], 
   FromDigits[Take[FromDigits[Take[y, {m}]], {2}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {2}]]}, {m, 1, 
   Count[x, _]}]
(* get {x12,y12,z12},{x22,y22,z22}... *)

h3 = Table[{FromDigits[Take[FromDigits[Take[x, {m}]], {3}]], 
   FromDigits[Take[FromDigits[Take[y, {m}]], {3}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {3}]]}, {m, 1, 
   Count[x, _]}]
(* get {x13,y13,z13},{x23,y23,z23}... *)

h123 = Table[{FromDigits[Take[FromDigits[Take[x, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[y, {m}]], {2}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {3}]]}, {m, 1, 
   Count[x, _]}]
(* get {x11,y12,z13},{x21,y22,z23}... *)

h321 = Table[{FromDigits[Take[FromDigits[Take[x, {m}]], {3}]], 
   FromDigits[Take[FromDigits[Take[y, {m}]], {2}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {1}]]}, {m, 1, 
   Count[x, _]}]
(* get {x13,y12,z11},{x23,y22,z21}... *)

enter image description here

Or we can change the order of x, y, z by swapping the letters within the code:

hzyx = Table[{FromDigits[Take[FromDigits[Take[z, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[y, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[x, {m}]], {1}]]}, {m, 1, 
   Count[x, _]}]
(* get {z11,y11,x11},{z21,y21,x21}... *)

hyzx = Table[{FromDigits[Take[FromDigits[Take[y, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {1}]], 
   FromDigits[Take[FromDigits[Take[x, {m}]], {1}]]}, {m, 1, 
   Count[x, _]}]
(* get {y11,z11,x11},{y21,z21,x21}... *)

enter image description here

Or even interpolate by doing both things, swapping x, y, z and positions simultaneously:

hy2z3x1 = 
 Table[{FromDigits[Take[FromDigits[Take[y, {m}]], {2}]], 
   FromDigits[Take[FromDigits[Take[z, {m}]], {3}]], 
   FromDigits[Take[FromDigits[Take[x, {m}]], {1}]]}, {m, 1, 
   Count[x, _]}]
(* get {y12,z13,x11},{y22,z23,x21}... *)

enter image description here

These are just a way to do multiple simultaneous interpolations, if anyone knows how to do this using faster or shorter codes can help in this topic? Thanks.

POSTED BY: Claudio Chaib
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract