4
$\begingroup$

everyone!

I have the "big" list of rules

{{{Subscript[Abx, 1, 1] -> 182.745, Subscript[Aby, 1, 1] -> -248.194, 
   Subscript[Abz, 1, 1] -> -4.84702}, {Subscript[Abx, 1, 2] -> 
    150.256, Subscript[Aby, 1, 2] -> -247.769, 
   Subscript[Abz, 1, 2] -> -9.55877}, {Subscript[Abx, 1, 3] -> 
    130.968, Subscript[Aby, 1, 3] -> -248.306, 
   Subscript[Abz, 1, 3] -> -8.02836}, {Subscript[Abx, 1, 4] -> 
    115.461, Subscript[Aby, 1, 4] -> -247.891, 
   Subscript[Abz, 1, 4] -> -6.00448}, {Subscript[Abx, 1, 5] -> 
    94.3148, Subscript[Aby, 1, 5] -> -244.614, 
   Subscript[Abz, 1, 5] -> -9.23579}, {Subscript[Abx, 1, 6] -> 
    58.1106, Subscript[Aby, 1, 6] -> -236.562, 
   Subscript[Abz, 1, 6] -> -23.471}}, {{Subscript[Abx, 2, 1] -> 
    177.762, Subscript[Aby, 2, 1] -> -237.093, 
   Subscript[Abz, 2, 1] -> -1.47293}, {Subscript[Abx, 2, 2] -> 
    147.416, Subscript[Aby, 2, 2] -> -231.738, 
   Subscript[Abz, 2, 2] -> 4.79013}, {Subscript[Abx, 2, 3] -> 126.022,
    Subscript[Aby, 2, 3] -> -229.455, 
   Subscript[Abz, 2, 3] -> 4.0303}, {Subscript[Abx, 2, 4] -> 109.183, 
   Subscript[Aby, 2, 4] -> -229.908, 
   Subscript[Abz, 2, 4] -> -1.66963}, {Subscript[Abx, 2, 5] -> 92.502,
    Subscript[Aby, 2, 5] -> -232.762, 
   Subscript[Abz, 2, 5] -> -10.2268}, {Subscript[Abx, 2, 6] -> 
    71.5825, Subscript[Aby, 2, 6] -> -237.681, 
   Subscript[Abz, 2, 6] -> -19.5586}}, {{Subscript[Abx, 3, 1] -> 
    170.779, Subscript[Aby, 3, 1] -> -215.335, 
   Subscript[Abz, 3, 1] -> -4.99162}, {Subscript[Abx, 3, 2] -> 146.77,
    Subscript[Aby, 3, 2] -> -207.336, 
   Subscript[Abz, 3, 2] -> 8.01939}, {Subscript[Abx, 3, 3] -> 125.545,
    Subscript[Aby, 3, 3] -> -204.549, 
   Subscript[Abz, 3, 3] -> 6.21291}, {Subscript[Abx, 3, 4] -> 106.328,
    Subscript[Aby, 3, 4] -> -206.149, 
   Subscript[Abz, 3, 4] -> -3.10462}, {Subscript[Abx, 3, 5] -> 
    88.3402, Subscript[Aby, 3, 5] -> -211.312, 
   Subscript[Abz, 3, 5] -> -12.6268}, {Subscript[Abx, 3, 6] -> 
    70.8046, Subscript[Aby, 3, 6] -> -219.213, 
   Subscript[Abz, 3, 6] -> -15.0471}}, {{Subscript[Abx, 4, 1] -> 
    164.148, Subscript[Aby, 4, 1] -> -188.286, 
   Subscript[Abz, 4, 1] -> -7.95539}, {Subscript[Abx, 4, 2] -> 
    146.115, Subscript[Aby, 4, 2] -> -181.987, 
   Subscript[Abz, 4, 2] -> 7.21463}, {Subscript[Abx, 4, 3] -> 125.914,
    Subscript[Aby, 4, 3] -> -180.715, 
   Subscript[Abz, 4, 3] -> 4.65974}, {Subscript[Abx, 4, 4] -> 104.484,
    Subscript[Aby, 4, 4] -> -182.838, 
   Subscript[Abz, 4, 4] -> -5.5832}, {Subscript[Abx, 4, 5] -> 82.7611,
    Subscript[Aby, 4, 5] -> -186.726, 
   Subscript[Abz, 4, 5] -> -13.4774}, {Subscript[Abx, 4, 6] -> 
    61.6855, Subscript[Aby, 4, 6] -> -190.747, 
   Subscript[Abz, 4, 6] -> -8.9859}}, {{Subscript[Abx, 5, 1] -> 
    163.686, Subscript[Aby, 5, 1] -> -146.81, 
   Subscript[Abz, 5, 1] -> 18.7636}, {Subscript[Abx, 5, 2] -> 136.162,
    Subscript[Aby, 5, 2] -> -168.316, 
   Subscript[Abz, 5, 2] -> 25.2557}, {Subscript[Abx, 5, 3] -> 113.207,
    Subscript[Aby, 5, 3] -> -174.851, 
   Subscript[Abz, 5, 3] -> 16.284}, {Subscript[Abx, 5, 4] -> 91.4897, 
   Subscript[Aby, 5, 4] -> -171.11, 
   Subscript[Abz, 5, 4] -> 3.60073}, {Subscript[Abx, 5, 5] -> 67.6774,
    Subscript[Aby, 5, 5] -> -161.788, 
   Subscript[Abz, 5, 5] -> -1.04208}, {Subscript[Abx, 5, 6] -> 
    38.4379, Subscript[Aby, 5, 6] -> -151.578, 
   Subscript[Abz, 5, 6] -> 14.1077}}, {{Subscript[Abx, 6, 1] -> 
    161.356, Subscript[Aby, 6, 1] -> -139.776, 
   Subscript[Abz, 6, 1] -> 17.5727}, {Subscript[Abx, 6, 2] -> 135.981,
    Subscript[Aby, 6, 2] -> -158.154, 
   Subscript[Abz, 6, 2] -> 21.8456}, {Subscript[Abx, 6, 3] -> 114.701,
    Subscript[Aby, 6, 3] -> -164.777, 
   Subscript[Abz, 6, 3] -> 14.9072}, {Subscript[Abx, 6, 4] -> 94.1792,
    Subscript[Aby, 6, 4] -> -162.452, 
   Subscript[Abz, 6, 4] -> 5.23384}, {Subscript[Abx, 6, 5] -> 71.078, 
   Subscript[Aby, 6, 5] -> -153.983, 
   Subscript[Abz, 6, 5] -> 1.30202}, {Subscript[Abx, 6, 6] -> 42.0599,
    Subscript[Aby, 6, 6] -> -142.175, 
   Subscript[Abz, 6, 6] -> 11.5881}}}//MatrixForm

And the "small" one:

{Subscript[Abx, 5, 4] -> 1, Subscript[Abx, 5, 5] -> 2}

Can you please show me, how to update the "big" list with the "small" list? I really tried to manipulate such functions and conceptions like Associations or KeySelect, but it doesn't work... I understand, that it should be some not very complicated solution.

Thank you!

$\endgroup$
5
  • $\begingroup$ And a little addition. I understand, that in my example I can manually change the rule I need, but the size of the lists (“big” and “small” ones) can change and become huge, so I’d really want to know how to do it in rational way… $\endgroup$ Apr 17 at 12:35
  • $\begingroup$ First, remove the //MatrixForm from the command as that gets in the way. Why not just Flatten the big list and then use Join? Like this big=your big list here and now do big2 = Flatten[big]; combined = Join[big2, small]; where small is your small list. ? Why do you need the big list to have dimensions {6,6,3}? $\endgroup$
    – Nasser
    Apr 17 at 12:42
  • $\begingroup$ “Big” is the matrix of control vertices of some Bezier surface, and it is very important not to lose its structure. $\endgroup$ Apr 17 at 12:48
  • $\begingroup$ Then may be you can explain the logic of trying to add a list of only 2 elements in a list of dimensions {6,6,3}? it is the wrong size in this case. Where will it go into the big list? I took you saying how to update the "big" list with the "small" list? to mean you want to add the small list into the big one. If you mean something else, may be you could clarify. $\endgroup$
    – Nasser
    Apr 17 at 12:51
  • $\begingroup$ A, OK! So, imagine that we have the "big" list as a storage for point coordinates. Then we preform some calculations and obtain that coordinates Abx5,4 and Abx5,5 should be recalculated with some values. In my example Abx5,4->1 and Abx5,5->2. So, after calculations and have to change the values of my storage (I mean my "big" list). So, before calculations Abx5,4-> 91.4897 and Abx5,5->67.6774 (it is all just for example), and after calculations 1 and 2 respectively. So, I need to "update" my "big" list with these new values. $\endgroup$ Apr 17 at 13:03

3 Answers 3

4
$\begingroup$

The original matrix of rules

(rules = {{{Subscript[Abx, 1, 1] -> 182.745, Subscript[Aby, 1, 1] -> -248.194,
        Subscript[Abz, 1, 1] -> -4.84702}, {Subscript[Abx, 1, 2] -> 150.256, 
       Subscript[Aby, 1, 2] -> -247.769, 
       Subscript[Abz, 1, 2] -> -9.55877}, {Subscript[Abx, 1, 3] -> 130.968, 
       Subscript[Aby, 1, 3] -> -248.306, 
       Subscript[Abz, 1, 3] -> -8.02836}, {Subscript[Abx, 1, 4] -> 115.461, 
       Subscript[Aby, 1, 4] -> -247.891, 
       Subscript[Abz, 1, 4] -> -6.00448}, {Subscript[Abx, 1, 5] -> 94.3148, 
       Subscript[Aby, 1, 5] -> -244.614, 
       Subscript[Abz, 1, 5] -> -9.23579}, {Subscript[Abx, 1, 6] -> 58.1106, 
       Subscript[Aby, 1, 6] -> -236.562, 
       Subscript[Abz, 1, 6] -> -23.471}}, {{Subscript[Abx, 2, 1] -> 177.762, 
       Subscript[Aby, 2, 1] -> -237.093, 
       Subscript[Abz, 2, 1] -> -1.47293}, {Subscript[Abx, 2, 2] -> 147.416, 
       Subscript[Aby, 2, 2] -> -231.738, 
       Subscript[Abz, 2, 2] -> 4.79013}, {Subscript[Abx, 2, 3] -> 126.022, 
       Subscript[Aby, 2, 3] -> -229.455, 
       Subscript[Abz, 2, 3] -> 4.0303}, {Subscript[Abx, 2, 4] -> 109.183, 
       Subscript[Aby, 2, 4] -> -229.908, 
       Subscript[Abz, 2, 4] -> -1.66963}, {Subscript[Abx, 2, 5] -> 92.502, 
       Subscript[Aby, 2, 5] -> -232.762, 
       Subscript[Abz, 2, 5] -> -10.2268}, {Subscript[Abx, 2, 6] -> 71.5825, 
       Subscript[Aby, 2, 6] -> -237.681, 
       Subscript[Abz, 2, 6] -> -19.5586}}, {{Subscript[Abx, 3, 1] -> 170.779, 
       Subscript[Aby, 3, 1] -> -215.335, 
       Subscript[Abz, 3, 1] -> -4.99162}, {Subscript[Abx, 3, 2] -> 146.77, 
       Subscript[Aby, 3, 2] -> -207.336, 
       Subscript[Abz, 3, 2] -> 8.01939}, {Subscript[Abx, 3, 3] -> 125.545, 
       Subscript[Aby, 3, 3] -> -204.549, 
       Subscript[Abz, 3, 3] -> 6.21291}, {Subscript[Abx, 3, 4] -> 106.328, 
       Subscript[Aby, 3, 4] -> -206.149, 
       Subscript[Abz, 3, 4] -> -3.10462}, {Subscript[Abx, 3, 5] -> 88.3402, 
       Subscript[Aby, 3, 5] -> -211.312, 
       Subscript[Abz, 3, 5] -> -12.6268}, {Subscript[Abx, 3, 6] -> 70.8046, 
       Subscript[Aby, 3, 6] -> -219.213, 
       Subscript[Abz, 3, 6] -> -15.0471}}, {{Subscript[Abx, 4, 1] -> 164.148, 
       Subscript[Aby, 4, 1] -> -188.286, 
       Subscript[Abz, 4, 1] -> -7.95539}, {Subscript[Abx, 4, 2] -> 146.115, 
       Subscript[Aby, 4, 2] -> -181.987, 
       Subscript[Abz, 4, 2] -> 7.21463}, {Subscript[Abx, 4, 3] -> 125.914, 
       Subscript[Aby, 4, 3] -> -180.715, 
       Subscript[Abz, 4, 3] -> 4.65974}, {Subscript[Abx, 4, 4] -> 104.484, 
       Subscript[Aby, 4, 4] -> -182.838, 
       Subscript[Abz, 4, 4] -> -5.5832}, {Subscript[Abx, 4, 5] -> 82.7611, 
       Subscript[Aby, 4, 5] -> -186.726, 
       Subscript[Abz, 4, 5] -> -13.4774}, {Subscript[Abx, 4, 6] -> 61.6855, 
       Subscript[Aby, 4, 6] -> -190.747, 
       Subscript[Abz, 4, 6] -> -8.9859}}, {{Subscript[Abx, 5, 1] -> 163.686, 
       Subscript[Aby, 5, 1] -> -146.81, 
       Subscript[Abz, 5, 1] -> 18.7636}, {Subscript[Abx, 5, 2] -> 136.162, 
       Subscript[Aby, 5, 2] -> -168.316, 
       Subscript[Abz, 5, 2] -> 25.2557}, {Subscript[Abx, 5, 3] -> 113.207, 
       Subscript[Aby, 5, 3] -> -174.851, 
       Subscript[Abz, 5, 3] -> 16.284}, {Subscript[Abx, 5, 4] -> 91.4897, 
       Subscript[Aby, 5, 4] -> -171.11, 
       Subscript[Abz, 5, 4] -> 3.60073}, {Subscript[Abx, 5, 5] -> 67.6774, 
       Subscript[Aby, 5, 5] -> -161.788, 
       Subscript[Abz, 5, 5] -> -1.04208}, {Subscript[Abx, 5, 6] -> 38.4379, 
       Subscript[Aby, 5, 6] -> -151.578, 
       Subscript[Abz, 5, 6] -> 14.1077}}, {{Subscript[Abx, 6, 1] -> 161.356, 
       Subscript[Aby, 6, 1] -> -139.776, 
       Subscript[Abz, 6, 1] -> 17.5727}, {Subscript[Abx, 6, 2] -> 135.981, 
       Subscript[Aby, 6, 2] -> -158.154, 
       Subscript[Abz, 6, 2] -> 21.8456}, {Subscript[Abx, 6, 3] -> 114.701, 
       Subscript[Aby, 6, 3] -> -164.777, 
       Subscript[Abz, 6, 3] -> 14.9072}, {Subscript[Abx, 6, 4] -> 94.1792, 
       Subscript[Aby, 6, 4] -> -162.452, 
       Subscript[Abz, 6, 4] -> 5.23384}, {Subscript[Abx, 6, 5] -> 71.078, 
       Subscript[Aby, 6, 5] -> -153.983, 
       Subscript[Abz, 6, 5] -> 1.30202}, {Subscript[Abx, 6, 6] -> 42.0599, 
       Subscript[Aby, 6, 6] -> -142.175, Subscript[Abz, 6, 6] -> 11.5881}}}) //
   MatrixForm;

The list of updates

update = {Subscript[Abx, 5, 4] -> 1, Subscript[Abx, 5, 5] -> 2};

For comparison, the current values are

(First /@ update) /. Flatten[rules]

(* {91.4897, 67.6774} *)

The updated rules

updatedRules = rules /. ((#[[1]] -> val_) :> # & /@ update);

Verifying that the rules have been updated

(First /@ update) /. Flatten[updatedRules]

(* {1, 2} *)
$\endgroup$
3
  • $\begingroup$ Thank you! Now I'm trying to understand your syntax...) I'm very noobie in Wolfram Language yet. $\endgroup$ Apr 17 at 13:30
  • $\begingroup$ For any unknown built-in symbols or operators, highlight them in Mathematica and press F1 for help $\endgroup$
    – Bob Hanlon
    Apr 17 at 13:33
  • $\begingroup$ I mean this manipulating with pure functions (I suppose all these "# and &" belong to that), it is something far for me yet... $\endgroup$ Apr 17 at 13:36
4
$\begingroup$

Try

bigList = {{Subscript[Abz, 5, 3] -> 16.284}, {Subscript[Abx, 5, 4] -> 
     91.4897, Subscript[Aby, 5, 4] -> -171.11, 
    Subscript[Abz, 5, 4] -> 3.60073}, {Subscript[Abx, 5, 5] -> 
     67.6774, Subscript[Aby, 5, 5] -> -161.788, 
    Subscript[Abz, 5, 5] -> -1.04208}};
smallList = {Subscript[Abx, 5, 4] -> 1, Subscript[Abx, 5, 5] -> 2};
newList = bigList /. {Rule[#[[1]], _] -> # & /@ smallList}

The syntax is that you are using the small list to create a substitution rule (/.{target->replacement}). You define a custom function (function[#]&) that takes the first element of each (/@) element (the elements are rules) in the short list and produces a match in the long list regardless of what the second element of the rule is there (the target is Rule[#,_]; it could also be written #->_) and substitutes that with the rule in the second list. This is performing the same function as Bob Hanlon's answer with trivial differences in the form of the expressions.

$\endgroup$
2
  • $\begingroup$ Thank you very much! $\endgroup$ Apr 17 at 14:08
  • $\begingroup$ @АлександрМиллер You are welcome. It is good form to accept answers that you consider helpful. $\endgroup$
    – Nicholas G
    Apr 17 at 15:08
3
$\begingroup$
rules = {{{Subscript[Abx, 1, 1] -> 182.745, 
    Subscript[Aby, 1, 1] -> -248.194, 
    Subscript[Abz, 1, 1] -> -4.84702}, {Subscript[Abx, 1, 2] -> 
     150.256, Subscript[Aby, 1, 2] -> -247.769, 
    Subscript[Abz, 1, 2] -> -9.55877}, {Subscript[Abx, 1, 3] -> 
     130.968, Subscript[Aby, 1, 3] -> -248.306, 
    Subscript[Abz, 1, 3] -> -8.02836}, {Subscript[Abx, 1, 4] -> 
     115.461, Subscript[Aby, 1, 4] -> -247.891, 
    Subscript[Abz, 1, 4] -> -6.00448}, {Subscript[Abx, 1, 5] -> 
     94.3148, Subscript[Aby, 1, 5] -> -244.614, 
    Subscript[Abz, 1, 5] -> -9.23579}, {Subscript[Abx, 1, 6] -> 
     58.1106, Subscript[Aby, 1, 6] -> -236.562, 
    Subscript[Abz, 1, 6] -> -23.471}}, {{Subscript[Abx, 2, 1] -> 
     177.762, Subscript[Aby, 2, 1] -> -237.093, 
    Subscript[Abz, 2, 1] -> -1.47293}, {Subscript[Abx, 2, 2] -> 
     147.416, Subscript[Aby, 2, 2] -> -231.738, 
    Subscript[Abz, 2, 2] -> 4.79013}, {Subscript[Abx, 2, 3] -> 
     126.022, Subscript[Aby, 2, 3] -> -229.455, 
    Subscript[Abz, 2, 3] -> 4.0303}, {Subscript[Abx, 2, 4] -> 109.183,
     Subscript[Aby, 2, 4] -> -229.908, 
    Subscript[Abz, 2, 4] -> -1.66963}, {Subscript[Abx, 2, 5] -> 
     92.502, Subscript[Aby, 2, 5] -> -232.762, 
    Subscript[Abz, 2, 5] -> -10.2268}, {Subscript[Abx, 2, 6] -> 
     71.5825, Subscript[Aby, 2, 6] -> -237.681, 
    Subscript[Abz, 2, 6] -> -19.5586}}, {{Subscript[Abx, 3, 1] -> 
     170.779, Subscript[Aby, 3, 1] -> -215.335, 
    Subscript[Abz, 3, 1] -> -4.99162}, {Subscript[Abx, 3, 2] -> 
     146.77, Subscript[Aby, 3, 2] -> -207.336, 
    Subscript[Abz, 3, 2] -> 8.01939}, {Subscript[Abx, 3, 3] -> 
     125.545, Subscript[Aby, 3, 3] -> -204.549, 
    Subscript[Abz, 3, 3] -> 6.21291}, {Subscript[Abx, 3, 4] -> 
     106.328, Subscript[Aby, 3, 4] -> -206.149, 
    Subscript[Abz, 3, 4] -> -3.10462}, {Subscript[Abx, 3, 5] -> 
     88.3402, Subscript[Aby, 3, 5] -> -211.312, 
    Subscript[Abz, 3, 5] -> -12.6268}, {Subscript[Abx, 3, 6] -> 
     70.8046, Subscript[Aby, 3, 6] -> -219.213, 
    Subscript[Abz, 3, 6] -> -15.0471}}, {{Subscript[Abx, 4, 1] -> 
     164.148, Subscript[Aby, 4, 1] -> -188.286, 
    Subscript[Abz, 4, 1] -> -7.95539}, {Subscript[Abx, 4, 2] -> 
     146.115, Subscript[Aby, 4, 2] -> -181.987, 
    Subscript[Abz, 4, 2] -> 7.21463}, {Subscript[Abx, 4, 3] -> 
     125.914, Subscript[Aby, 4, 3] -> -180.715, 
    Subscript[Abz, 4, 3] -> 4.65974}, {Subscript[Abx, 4, 4] -> 
     104.484, Subscript[Aby, 4, 4] -> -182.838, 
    Subscript[Abz, 4, 4] -> -5.5832}, {Subscript[Abx, 4, 5] -> 
     82.7611, Subscript[Aby, 4, 5] -> -186.726, 
    Subscript[Abz, 4, 5] -> -13.4774}, {Subscript[Abx, 4, 6] -> 
     61.6855, Subscript[Aby, 4, 6] -> -190.747, 
    Subscript[Abz, 4, 6] -> -8.9859}}, {{Subscript[Abx, 5, 1] -> 
     163.686, Subscript[Aby, 5, 1] -> -146.81, 
    Subscript[Abz, 5, 1] -> 18.7636}, {Subscript[Abx, 5, 2] -> 
     136.162, Subscript[Aby, 5, 2] -> -168.316, 
    Subscript[Abz, 5, 2] -> 25.2557}, {Subscript[Abx, 5, 3] -> 
     113.207, Subscript[Aby, 5, 3] -> -174.851, 
    Subscript[Abz, 5, 3] -> 16.284}, {Subscript[Abx, 5, 4] -> 91.4897,
     Subscript[Aby, 5, 4] -> -171.11, 
    Subscript[Abz, 5, 4] -> 3.60073}, {Subscript[Abx, 5, 5] -> 
     67.6774, Subscript[Aby, 5, 5] -> -161.788, 
    Subscript[Abz, 5, 5] -> -1.04208}, {Subscript[Abx, 5, 6] -> 
     38.4379, Subscript[Aby, 5, 6] -> -151.578, 
    Subscript[Abz, 5, 6] -> 14.1077}}, {{Subscript[Abx, 6, 1] -> 
     161.356, Subscript[Aby, 6, 1] -> -139.776, 
    Subscript[Abz, 6, 1] -> 17.5727}, {Subscript[Abx, 6, 2] -> 
     135.981, Subscript[Aby, 6, 2] -> -158.154, 
    Subscript[Abz, 6, 2] -> 21.8456}, {Subscript[Abx, 6, 3] -> 
     114.701, Subscript[Aby, 6, 3] -> -164.777, 
    Subscript[Abz, 6, 3] -> 14.9072}, {Subscript[Abx, 6, 4] -> 
     94.1792, Subscript[Aby, 6, 4] -> -162.452, 
    Subscript[Abz, 6, 4] -> 5.23384}, {Subscript[Abx, 6, 5] -> 71.078,
     Subscript[Aby, 6, 5] -> -153.983, 
    Subscript[Abz, 6, 5] -> 1.30202}, {Subscript[Abx, 6, 6] -> 
     42.0599, Subscript[Aby, 6, 6] -> -142.175, 
    Subscript[Abz, 6, 6] -> 11.5881}}}

update = {Subscript[Abx, 5, 4] -> 1, Subscript[Abx, 5, 5] -> 2}

pos = Level[(Most /@ Position[rules, First@#] & /@ update), {-2}]

These are the positions where replacements happen:

{{5, 4, 1}, {5, 5, 1}}

ReplacePart[rules, Thread[pos -> update]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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