Wolfram mathematica 用mathematica很好地打印出一个矩阵
我在mathematica有一个列表(矩阵)。我想很好地打印出来,每行的最大值用粗体表示。如何做到这一点Wolfram mathematica 用mathematica很好地打印出一个矩阵,wolfram-mathematica,Wolfram Mathematica,我在mathematica有一个列表(矩阵)。我想很好地打印出来,每行的最大值用粗体表示。如何做到这一点 或者更进一步,如果在这样的最大值之外有一个圆,这是可能的吗?您可以使用MatrixForm很好地打印出矩阵: data = RandomInteger[100, {5, 5}]; data // MatrixForm 屈服 可以围绕每行中的最大值绘制一个圆,如下所示: Map[# /. m : Max[#] :> Framed[m, RoundingRadius -> 10
或者更进一步,如果在这样的最大值之外有一个圆,这是可能的吗?您可以使用
MatrixForm
很好地打印出矩阵:
data = RandomInteger[100, {5, 5}];
data // MatrixForm
屈服
可以围绕每行中的最大值绘制一个圆,如下所示:
Map[# /. m : Max[#] :> Framed[m, RoundingRadius -> 1000] &, data] //
MatrixForm
屈服
RoundingRadius->1000
使用了一个大得离谱的参数来获取圆。您可能需要根据显示器的比例调整常数
如果您喜欢加粗,可以使用
样式[m,粗体]
更改框[m..]
。栅格[]可对显示外观进行精细控制。例如:
g[a_] := Grid[a,
Background -> {None, {{LightBlue, LightRed}}},
Dividers -> {False, All},
ItemStyle -> {Automatic, Automatic,
MapIndexed[Flatten@{#2, Ordering[#1, -1]} -> {Bold, Red} &, a]}]
g[RandomInteger[100, {10, 7}]]
g[a_] := Grid[a,
Background -> {None, {{LightBlue, LightRed}}},
Dividers -> {False, All},
ItemStyle -> {Automatic, Automatic,
Flatten[Tuples[{First@#, Last@#}] & /@
MapIndexed[{#2, Position[#1, Max[#1]]} &, a],
1] /. {q_, {r_}} -> ({q, r} -> {Red, Bold})}]
注意:每行只高亮显示一个元素
编辑
要高亮显示每个max元素,可以执行以下操作,例如:
g[a_] := Grid[a,
Background -> {None, {{LightBlue, LightRed}}},
Dividers -> {False, All},
ItemStyle -> {Automatic, Automatic,
MapIndexed[Flatten@{#2, Ordering[#1, -1]} -> {Bold, Red} &, a]}]
g[RandomInteger[100, {10, 7}]]
g[a_] := Grid[a,
Background -> {None, {{LightBlue, LightRed}}},
Dividers -> {False, All},
ItemStyle -> {Automatic, Automatic,
Flatten[Tuples[{First@#, Last@#}] & /@
MapIndexed[{#2, Position[#1, Max[#1]]} &, a],
1] /. {q_, {r_}} -> ({q, r} -> {Red, Bold})}]
我喜欢
#/。m:Max[#]->…
构造。(+1)+1,我要花一点时间才能弄明白为什么您的第一个示例只突出显示了一个元素。@rcollyer这一点并不神秘。排序[l,-1]只返回一个元素。啊,我明白了MapIndexed
返回一个列表,其中的元素形式为{row\u num,first\u max\u pos}->{Bold,Red}
。