How to pretty print in ipython notebook via sympy?

后端 未结 4 1991
迷失自我
迷失自我 2020-12-05 03:57

I tried pprint, print, the former only prints Unicode version, and the latter doesn\'t do pretty prints.

from sympy import symbols         


        
4条回答
  •  自闭症患者
    2020-12-05 04:54

    I have asked a similar question (now linked to this one). After reading the answers and tinkering a bit, I conclude that there are 3 types of output one can get:

    1. "Not pretty", pure text... "low quality". This is what one obtains with print(expression)

    2. Pretty, pure text... "medium quality". This is what one obtains with

       import sympy as sym
       sympy.pprint(expression)
      

    It still uses the same font and uses only characters to put together the mathematical expression. But it can, e.g., raise numbers for powers, pull fractions by laying out the horizontal line, etc.

    1. Pretty, with graphics, symbols, etc... "high quality". This is what one obtains with

       import IPython.display as disp
       disp.display(expression)
      

    This is the same as what one obtains as an output of the notebook cell, but now as a result of a command. Then, one can have multiple such outputs from a single notebook cell.

    It is worth noting that:

    1. sym.init_printing(... affects the output of sym.pprint.

    2. sym.latex(expression) produces a LaTeX string for the expression. disp.Math(... produces the expression from LaTeX. These two may come in useful. Thus, disp.display(disp.Math(sym.latex(expression))) would produce the same output as disp.display(expression).

提交回复
热议问题