# Manipulating Linear Tables with Multiple External Intervals and Quantities

Posted 1 month ago
357 Views
|
3 Replies
|
2 Total Likes
|
 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]] 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} *) 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} *) ListPlot[r1] (* before random permutation *) ListPlot[r2] (* after random permutation *) 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} *) ListPlot[r21] (* before random permutation *) ListPlot[r22] (* after random permutation *) 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.
3 Replies
Sort By:
Posted 1 month ago
 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}... *) 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}... *) 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}... *) 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.