Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format mathematica output a list of results

I have a list of expressions that operate on data.

Min[data]
Max[data]
Covariance[data, data1]
Mean[data]
GeometricMean[data]
Total[data]
Sum[Log[data[[i]]], {i, 1, Length[data]}]
Sum[(data[[i]])^2, {i, 1, Length[data]}]

The output looks like this

Out[1]= 1.9
Out[2]= 3.1
....

Is it possible to show the result along with its expression? For example

Min[data] = 1.9
Max[data] = 3.1
....

Any advice on how to format that kind of output for easy reading is welcome!

like image 602
Wei Shi Avatar asked Jun 29 '11 15:06

Wei Shi


1 Answers

You could use

$PrePrint = 
  Function[a, 
   Row[{ToExpression[InString[$Line], StandardForm, HoldForm], " = ", 
     a}]];

which is fine for small inputs, but perhaps not what you want for multiline inputs.

enter image description here

(You can turn this off again with Unset[$PrePrint])

like image 181
Brett Champion Avatar answered Oct 28 '22 13:10

Brett Champion