开发者

nicely print out a matrix in mathematica

I have a list of lists (开发者_如何学Cmatrix) in mathematica. I want to print it out nicely, with the max in every row in bold. How to do this?

Or maybe even further, with a circle outside such max, is this possible?


You can use MatrixForm to print out matrices nicely:

data = RandomInteger[100, {5, 5}];

data // MatrixForm

yields

nicely print out a matrix in mathematica

You can draw a circle around the maximum in each row as follows:

Map[# /. m : Max[#] :> Framed[m, RoundingRadius -> 1000]  &, data] //
  MatrixForm

yielding

nicely print out a matrix in mathematica

RoundingRadius -> 1000 uses a ridiculously large parameter to get circles. You may need to adjust the constant depending upon the scale of your display.

You can change Framed[m...] with Style[m, Bold] if you prefer bolding.


Grid[ ] gives you fine grain control on the display appearance. For example:

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}]]  

nicely print out a matrix in mathematica

NB> It'll highlight only one element per row

Edit

To highlight every max element, you could do for example:

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})}]  

nicely print out a matrix in mathematica

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜