Skip to main content
deleted 32 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Sort@Tally@Flatten@MapThread[#[#2][[1]]Sort &,@ {rankofnearestF,Tally databt},@ 3]Flatten @ ranksofnearest
Sort@Tally@Flatten@MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3]
Sort @ Tally @ Flatten @ ranksofnearest
deleted 23 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
SeedRandom[1]
dim = 3; mats = 4; n = 3;
databdata = RandomVariate[dist[2, 1], {n, mats, dim, dim}];
databt = RandomVariate[dist[2, 1], {n, mats, dim}];

datab == data

True

TeXForm[datab]TeXForm[data]
nearestvalueF = Map[Nearest, databdata, {3}];
nearestvalues = MapThread[#[#2][[1]] &, {nearestvalueF, databt}, 3];
TeXForm[nearestvalues]
rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, databdata, {3}];
ranksofnearest = MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3];
TeXForm[ranksofnearest]
Legended[MatrixForm[Map[Style[#[[1]], (#[[2]] /. {1 -> Red, 2 -> Green, 3 -> Blue})] &, 
    combined, {-2}], TableDirections -> Row]]], 
 Placed[Column[Style @@@ Transpose[{{"rank", "first", "second", "third"}, 
   {{Black, 16}, Red, Green, Blue}}], Dividers -> {False, 2 -> True}], Right]]

enter image description hereenter image description here

nearestValuesAndRanksF = Map[Nearest[Sort[#] -> {"Element","Index"}] &, databdata, {3}];
combined2 = MapThread[#[#2][[1]] &, {nearestValuesAndRanksF, databt}, 3];
combined2 == combined
SeedRandom[1]
dim = 3; mats = 4; n = 3;
datab = RandomVariate[dist[2, 1], {n, mats, dim, dim}];
databt = RandomVariate[dist[2, 1], {n, mats, dim}];

datab == data

True

TeXForm[datab]
nearestvalueF = Map[Nearest, datab, {3}];
nearestvalues = MapThread[#[#2][[1]] &, {nearestvalueF, databt}, 3];
TeXForm[nearestvalues]
rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, datab, {3}];
ranksofnearest = MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3];
TeXForm[ranksofnearest]
Legended[MatrixForm[Map[Style[#[[1]], (#[[2]] /. {1 -> Red, 2 -> Green, 3 -> Blue})] &, 
   combined, {-2}], TableDirections -> Row], 
 Placed[Column[Style @@@ Transpose[{{"rank", "first", "second", "third"}, 
   {{Black, 16}, Red, Green, Blue}}], Dividers -> {False, 2 -> True}], Right]]

enter image description here

nearestValuesAndRanksF = Map[Nearest[Sort[#] -> {"Element","Index"}] &, datab, {3}];
combined2 = MapThread[#[#2][[1]] &, {nearestValuesAndRanksF, databt}, 3];
combined2 == combined
SeedRandom[1]
dim = 3; mats = 4; n = 3;
data = RandomVariate[dist[2, 1], {n, mats, dim, dim}];
databt = RandomVariate[dist[2, 1], {n, mats, dim}];


TeXForm[data]
nearestvalueF = Map[Nearest, data, {3}];
nearestvalues = MapThread[#[#2][[1]] &, {nearestvalueF, databt}, 3];
TeXForm[nearestvalues]
rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, data, {3}];
ranksofnearest = MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3];
TeXForm[ranksofnearest]
Legended[MatrixForm[Map[Style[#[[1]], (#[[2]] /. {1 -> Red, 2 -> Green, 3 -> Blue})] &, 
    combined, {-2}]], 
 Placed[Column[Style @@@ Transpose[{{"rank", "first", "second", "third"}, 
   {{Black, 16}, Red, Green, Blue}}], Dividers -> {False, 2 -> True}], Right]]

enter image description here

nearestValuesAndRanksF = Map[Nearest[Sort[#] -> {"Element","Index"}] &, data, {3}];
combined2 = MapThread[#[#2][[1]] &, {nearestValuesAndRanksF, databt}, 3];
combined2 == combined
added 25 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, datab, {3}];TeXForm[datab]

$$\tiny\left( \begin{array}{cccc} \left( \begin{array}{ccc} 0.449043 & 1.48137 & 0.48613 \\ 1.2932 & 1.19225 & 1.64987 \\ 0.782326 & 1.21024 & 0.962458 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.596656 & 1.24579 & 0.538028 \\ 0.927759 & 1.18168 & 0.151963 \\ 0.438377 & 0.278683 & 0.740327 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.10816 & 1.25299 & 0.737502 \\ 1.43155 & 1.08755 & 0.582804 \\ 0.969597 & 0.445523 & 1.05965 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.72258 & 0.810115 & 1.33333 \\ 0.865783 & 0.462852 & 2.10634 \\ 1.07203 & 0.485768 & 2.10349 \\ \end{array} \right) \\ \left( \begin{array}{ccc} 0.96868 & 0.882563 & 0.882634 \\ 0.56402 & 0.484774 & 1.15524 \\ 1.10104 & 0.901214 & 1.70141 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.85481 & 0.550826 & 1.26273 \\ 0.779351 & 0.758341 & 0.51416 \\ 0.164397 & 1.29721 & 0.815494 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.05785 & 1.26957 & 0.784296 \\ 0.876061 & 1.13112 & 0.775078 \\ 0.750277 & 0.782584 & 0.38401 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.636682 & 1.13854 & 0.666643 \\ 0.596915 & 1.05141 & 1.80751 \\ 1.5429 & 0.625666 & 0.935543 \\ \end{array} \right) \\ \left( \begin{array}{ccc} 0.182974 & 0.560791 & 1.04689 \\ 0.426948 & 0.308514 & 0.603491 \\ 1.26573 & 0.401616 & 0.632274 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.22939 & 0.869507 & 1.23884 \\ 0.738202 & 0.753391 & 2.00657 \\ 0.240648 & 0.722363 & 1.55349 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.35294 & 0.717737 & 1.27567 \\ 0.806159 & 1.00854 & 1.46412 \\ 1.40222 & 1.20532 & 0.663839 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.81562 & 0.775681 & 1.38224 \\ 0.843356 & 1.44941 & 0.452277 \\ 0.79226 & 1.07275 & 0.771253 \\ \end{array} \right) \\ \end{array} \right)$$

nearestvalueF = Map[Nearest, datab, {3}];
nearestvalues = MapThread[#[#2][[1]] &, {nearestvalueF, databt}, 3];
TeXForm[nearestvalues]

$$\tiny\left( \begin{array}{cccc} \{0.449043,1.19225,0.782326\} & \{0.538028,1.18168,0.740327\} & \{0.737502,1.08755,1.05965\} & \{1.33333,0.865783,0.485768\} \\ \{0.96868,0.484774,0.901214\} & \{0.85481,0.51416,0.164397\} & \{1.26957,1.13112,0.38401\} & \{0.636682,1.05141,0.935543\} \\ \{0.182974,0.426948,1.26573\} & \{1.22939,0.738202,0.240648\} & \{0.717737,1.46412,1.20532\} & \{1.38224,0.452277,0.771253\} \\ \end{array} \right)$$

rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, datab, {3}];
ranksofnearest = MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3];
TeXForm[ranksofnearest]

$$\left( \begin{array}{cccc} \{1,1,1\} & \{1,3,3\} & \{1,2,3\} & \{3,2,1\} \\ \{3,1,1\} & \{2,1,1\} & \{3,3,1\} & \{1,2,2\} \\ \{1,2,3\} & \{2,1,1\} & \{1,3,2\} & \{2,1,1\} \\ \end{array} \right)$$

combined = MapThread[List, {nearestvalues, ranksofnearest}, 3];
rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, datab, {3}];
nearestvalueF = Map[Nearest, datab, {3}];
nearestvalues = MapThread[#[#2][[1]] &, {nearestvalueF, databt}, 3];
ranksofnearest = MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3];
combined = MapThread[List, {nearestvalues, ranksofnearest}, 3];
TeXForm[datab]

$$\tiny\left( \begin{array}{cccc} \left( \begin{array}{ccc} 0.449043 & 1.48137 & 0.48613 \\ 1.2932 & 1.19225 & 1.64987 \\ 0.782326 & 1.21024 & 0.962458 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.596656 & 1.24579 & 0.538028 \\ 0.927759 & 1.18168 & 0.151963 \\ 0.438377 & 0.278683 & 0.740327 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.10816 & 1.25299 & 0.737502 \\ 1.43155 & 1.08755 & 0.582804 \\ 0.969597 & 0.445523 & 1.05965 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.72258 & 0.810115 & 1.33333 \\ 0.865783 & 0.462852 & 2.10634 \\ 1.07203 & 0.485768 & 2.10349 \\ \end{array} \right) \\ \left( \begin{array}{ccc} 0.96868 & 0.882563 & 0.882634 \\ 0.56402 & 0.484774 & 1.15524 \\ 1.10104 & 0.901214 & 1.70141 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.85481 & 0.550826 & 1.26273 \\ 0.779351 & 0.758341 & 0.51416 \\ 0.164397 & 1.29721 & 0.815494 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.05785 & 1.26957 & 0.784296 \\ 0.876061 & 1.13112 & 0.775078 \\ 0.750277 & 0.782584 & 0.38401 \\ \end{array} \right) & \left( \begin{array}{ccc} 0.636682 & 1.13854 & 0.666643 \\ 0.596915 & 1.05141 & 1.80751 \\ 1.5429 & 0.625666 & 0.935543 \\ \end{array} \right) \\ \left( \begin{array}{ccc} 0.182974 & 0.560791 & 1.04689 \\ 0.426948 & 0.308514 & 0.603491 \\ 1.26573 & 0.401616 & 0.632274 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.22939 & 0.869507 & 1.23884 \\ 0.738202 & 0.753391 & 2.00657 \\ 0.240648 & 0.722363 & 1.55349 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.35294 & 0.717737 & 1.27567 \\ 0.806159 & 1.00854 & 1.46412 \\ 1.40222 & 1.20532 & 0.663839 \\ \end{array} \right) & \left( \begin{array}{ccc} 1.81562 & 0.775681 & 1.38224 \\ 0.843356 & 1.44941 & 0.452277 \\ 0.79226 & 1.07275 & 0.771253 \\ \end{array} \right) \\ \end{array} \right)$$

nearestvalueF = Map[Nearest, datab, {3}];
nearestvalues = MapThread[#[#2][[1]] &, {nearestvalueF, databt}, 3];
TeXForm[nearestvalues]

$$\tiny\left( \begin{array}{cccc} \{0.449043,1.19225,0.782326\} & \{0.538028,1.18168,0.740327\} & \{0.737502,1.08755,1.05965\} & \{1.33333,0.865783,0.485768\} \\ \{0.96868,0.484774,0.901214\} & \{0.85481,0.51416,0.164397\} & \{1.26957,1.13112,0.38401\} & \{0.636682,1.05141,0.935543\} \\ \{0.182974,0.426948,1.26573\} & \{1.22939,0.738202,0.240648\} & \{0.717737,1.46412,1.20532\} & \{1.38224,0.452277,0.771253\} \\ \end{array} \right)$$

rankofnearestF = Map[Nearest[Sort[#] -> Automatic] &, datab, {3}];
ranksofnearest = MapThread[#[#2][[1]] &, {rankofnearestF, databt}, 3];
TeXForm[ranksofnearest]

$$\left( \begin{array}{cccc} \{1,1,1\} & \{1,3,3\} & \{1,2,3\} & \{3,2,1\} \\ \{3,1,1\} & \{2,1,1\} & \{3,3,1\} & \{1,2,2\} \\ \{1,2,3\} & \{2,1,1\} & \{1,3,2\} & \{2,1,1\} \\ \end{array} \right)$$

combined = MapThread[List, {nearestvalues, ranksofnearest}, 3];
added 25 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 3 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 1659 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 467 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading