Skip to main content
edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
 t2 = DeleteDuplicates[RandomInteger[3DeleteDuplicates[RandomInteger[5, {5, 3}], #1[[;; 2]] == #2[[;; 2]] &]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)
 t2 = DeleteDuplicates[RandomInteger[3, {5, 3}], #1[[;; 2]] == #2[[;; 2]] &]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)
 t2 = DeleteDuplicates[RandomInteger[5, {5, 3}], #1[[;; 2]] == #2[[;; 2]] &]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)
added 151 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
 t1 = Table[{x, y, 0.}, {x, 0, 5}, {y, 0, 5}]
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 0.}},
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4,  0.}, {1, 5, 0.}}, 
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3,  0.}, {2, 4, 0.}, {2, 5, 0.}}, 
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 0.}, {4, 4, 0.}, {4, 5, 0.}}, 
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0.}, {5, 4, 0.}, {5, 5, 0.}}} *)

Use the second table, say,

 t2 = RandomInteger[5DeleteDuplicates[RandomInteger[3, {5, 3}], #1[[;; 2]] == #2[[;; 2]] &]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)

to define the replacement rules:

 rplcmntRule = {#[[1]], #[[2]], _} -> # & /@ t2
 (*  {{0, 5, _} -> {0, 5, 3}, {4, 3, _} -> {4, 3, 3}, 
      {1, 4, _} -> {1, 4, 4}, {5, 3, _} -> {5, 3, 0}, {2, 5, _} -> {2, 5, 3}}*)

and use them in ReplaceAll:

 t1 /. rplcmntRule
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 3}}, 
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4, 4}, {1, 5, 0.}},
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3, 0.}, {2, 4, 0.}, {2, 5, 3}},
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 3}, {4, 4, 0.}, {4, 5, 0.}},
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0}, {5, 4, 0.}, {5, 5, 0.}}} *)
 t1 = Table[{x, y, 0.}, {x, 0, 5}, {y, 0, 5}]
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 0.}},
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4,  0.}, {1, 5, 0.}}, 
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3,  0.}, {2, 4, 0.}, {2, 5, 0.}}, 
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 0.}, {4, 4, 0.}, {4, 5, 0.}}, 
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0.}, {5, 4, 0.}, {5, 5, 0.}}} *)
 t2 = RandomInteger[5, {5, 3}]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)
 rplcmntRule = {#[[1]], #[[2]], _} -> # & /@ t2
 (*  {{0, 5, _} -> {0, 5, 3}, {4, 3, _} -> {4, 3, 3}, 
      {1, 4, _} -> {1, 4, 4}, {5, 3, _} -> {5, 3, 0}, {2, 5, _} -> {2, 5, 3}}*)
 t1 /. rplcmntRule
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 3}}, 
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4, 4}, {1, 5, 0.}},
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3, 0.}, {2, 4, 0.}, {2, 5, 3}},
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 3}, {4, 4, 0.}, {4, 5, 0.}},
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0}, {5, 4, 0.}, {5, 5, 0.}}} *)
 t1 = Table[{x, y, 0.}, {x, 0, 5}, {y, 0, 5}]
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 0.}},
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4,  0.}, {1, 5, 0.}}, 
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3,  0.}, {2, 4, 0.}, {2, 5, 0.}}, 
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 0.}, {4, 4, 0.}, {4, 5, 0.}}, 
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0.}, {5, 4, 0.}, {5, 5, 0.}}} *)

Use the second table, say,

 t2 = DeleteDuplicates[RandomInteger[3, {5, 3}], #1[[;; 2]] == #2[[;; 2]] &]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)

to define the replacement rules:

 rplcmntRule = {#[[1]], #[[2]], _} -> # & /@ t2
 (*  {{0, 5, _} -> {0, 5, 3}, {4, 3, _} -> {4, 3, 3}, 
      {1, 4, _} -> {1, 4, 4}, {5, 3, _} -> {5, 3, 0}, {2, 5, _} -> {2, 5, 3}}*)

and use them in ReplaceAll:

 t1 /. rplcmntRule
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 3}}, 
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4, 4}, {1, 5, 0.}},
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3, 0.}, {2, 4, 0.}, {2, 5, 3}},
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 3}, {4, 4, 0.}, {4, 5, 0.}},
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0}, {5, 4, 0.}, {5, 5, 0.}}} *)
added 1230 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
 t1 = Table[{x, y, 0.}, {x, 0, 5}, {y, 0, 5}]
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 0.}},
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4,  0.}, {1, 5, 0.}}, 
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3,  0.}, {2, 4, 0.}, {2, 5, 0.}}, 
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 0.}, {4, 4, 0.}, {4, 5, 0.}}, 
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0.}, {5, 4, 0.}, {5, 5, 0.}}} *)
 t2 = RandomInteger[5, {5, 3}]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)
 rplcmntRule = {#[[1]], #[[2]], _} -> # & /@ t2
 (*  {{0, 5, _} -> {0, 5, 3}, {4, 3, _} -> {4, 3, 3}, 
      {1, 4, _} -> {1, 4, 4}, {5, 3, _} -> {5, 3, 0}, {2, 5, _} -> {2, 5, 3}}*)
 t1 /. rplcmntRule
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 3}}, 
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4, 4}, {1, 5, 0.}},
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3, 0.}, {2, 4, 0.}, {2, 5, 3}},
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 3}, {4, 4, 0.}, {4, 5, 0.}},
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0}, {5, 4, 0.}, {5, 5, 0.}}} *)
 t1 = Table[{x, y, 0.}, {x, 0, 5}, {y, 0, 5}]
 t2 = RandomInteger[5, {5, 3}]
 rplcmntRule = {#[[1]], #[[2]], _} -> # & /@ t2
 t1 /. rplcmntRule
 t1 = Table[{x, y, 0.}, {x, 0, 5}, {y, 0, 5}]
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 0.}},
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4,  0.}, {1, 5, 0.}}, 
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3,  0.}, {2, 4, 0.}, {2, 5, 0.}}, 
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 0.}, {4, 4, 0.}, {4, 5, 0.}}, 
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0.}, {5, 4, 0.}, {5, 5, 0.}}} *)
 t2 = RandomInteger[5, {5, 3}]
 (* {{0, 5, 3}, {4, 3, 3}, {1, 4, 4}, {5, 3, 0}, {2, 5, 3}} *)
 rplcmntRule = {#[[1]], #[[2]], _} -> # & /@ t2
 (*  {{0, 5, _} -> {0, 5, 3}, {4, 3, _} -> {4, 3, 3}, 
      {1, 4, _} -> {1, 4, 4}, {5, 3, _} -> {5, 3, 0}, {2, 5, _} -> {2, 5, 3}}*)
 t1 /. rplcmntRule
 (* {{{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {0, 4, 0.}, {0, 5, 3}}, 
     {{1, 0, 0.}, {1, 1, 0.}, {1, 2, 0.}, {1, 3, 0.}, {1, 4, 4}, {1, 5, 0.}},
     {{2, 0, 0.}, {2, 1, 0.}, {2, 2, 0.}, {2, 3, 0.}, {2, 4, 0.}, {2, 5, 3}},
     {{3, 0, 0.}, {3, 1, 0.}, {3, 2, 0.}, {3, 3, 0.}, {3, 4, 0.}, {3, 5, 0.}}, 
     {{4, 0, 0.}, {4, 1, 0.}, {4, 2, 0.}, {4, 3, 3}, {4, 4, 0.}, {4, 5, 0.}},
     {{5, 0, 0.}, {5, 1, 0.}, {5, 2, 0.}, {5, 3, 0}, {5, 4, 0.}, {5, 5, 0.}}} *)
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading