K i.TddlmZddlmZddlmZddlmZddlm Z GddZ y) )Tuple)S)Symbol) SympifyError) FunctionTypec@eZdZdZdZdZdZdZdZdZ dZ d Z y ) TableForma Create a nice table representation of data. Examples ======== >>> from sympy import TableForm >>> t = TableForm([[5, 7], [4, 2], [10, 3]]) >>> print(t) 5 7 4 2 10 3 You can use the SymPy's printing system to produce tables in any format (ascii, latex, html, ...). >>> print(t.as_latex()) \begin{tabular}{l l} $5$ & $7$ \\ $4$ & $2$ \\ $10$ & $3$ \\ \end{tabular} c ddlm}t||r|j}t |}|j dd}d}|d}d}t |}td|D}t|D]d\}} t | |k7r!| j|g|t | z zt| D]\} } | |s|} n t| } | | | <| ||<ft|D cgc] } t|  c} } |j d ddg}|d k(rtd |d ztd |d zg}n1|\}}|d k(rtd |d z}|d k(rtd |d z}||g}d }|j d d}d}||}||vr|g|z}n4g}|D]-}||}|j||d vs!t!d|z|drt ||d zk(r |d}|d d}nd}t ||k7rt!d|dt ||j ddg|z}|j dd}||_||_| |_||_||_||_||_||_y#t$rt t| } YwxYwcc} w)a Creates a TableForm. Parameters: data ... 2D data to be put into the table; data can be given as a Matrix headings ... gives the labels for rows and columns: Can be a single argument that applies to both dimensions: - None ... no labels - "automatic" ... labels are 1, 2, 3, ... Can be a list of labels for rows and columns: The labels for each dimension can be given as None, "automatic", or [l1, l2, ...] e.g. ["automatic", None] will number the rows [default: None] alignments ... alignment of the columns with: - "left" or "<" - "center" or "^" - "right" or ">" When given as a single value, the value is used for all columns. The row headings (if given) will be right justified unless an explicit alignment is given for it and all other columns. [default: "left"] formats ... a list of format strings or functions that accept 3 arguments (entry, row number, col number) and return a string for the table entry. (If a function returns None then the _print method will be used.) wipe_zeros ... Do not show zeros in the table. [default: True] pad ... the string to use to indicate a missing value (e.g. elements that are None or those that are missing from the end of a row (i.e. any row that is shorter than the rest is assumed to have missing values). When None, nothing will be shown for values that are missing from the end of a row; values that are None, however, will be shown. [default: None] Examples ======== >>> from sympy import TableForm, Symbol >>> TableForm([[5, 7], [4, 2], [10, 3]]) 5 7 4 2 10 3 >>> TableForm([list('.'*i) for i in range(1, 4)], headings='automatic') | 1 2 3 --------- 1 | . 2 | . . 3 | . . . >>> TableForm([[Symbol('.'*(j if not i%2 else 1)) for i in range(3)] ... for j in range(4)], alignments='rcl') . . . . .. . .. ... . ... rMatrixpadNF Tc32K|]}t|ywNlen).0lines ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/printing/tableform.py z%TableForm.__init__..s,tT,headings automatic)lrc alignmentsrc|jj}t|dkDrddddj||Sddddj||S)Nrrrr)leftrightcenter)<>^)striplowerrget)as r _std_alignz&TableForm.__init__.._std_alignsS !A1vz #cSAEEaKK s599!Q??zalignment "%s" unrecognizedrz%wrong number of alignments: expected z but got formats wipe_zeros)sympy.matrices.denser isinstancetolistrr(rmax enumerateextendrrstrrrangeappend ValueError_w_h_lines _headings _head_align _alignments_column_formats _wipe_zeros)selfdatakwargr r9r ok_Noner8irjljdr:rr;h1h2allowrr* std_alignr=r)r<r>r?s r__init__zTableForm.__init__#sf 0 dF #;;=D Yiit$ ;CGSk ,t, ,  GAt4yB SE2D >23"4 2:" -rUQ DG D1q1299Z$6 { "q"q&)5BF+; I& J &JJc"ddlm}||dSNr)sstr)orderr4rOr@rOs r__repr__zTableForm.__repr__D%%r+c"ddlm}||dSrNrQrRs r__str__zTableForm.__str__rTr+c2ddlm}||jS)aReturns the data of the table in Matrix form. Examples ======== >>> from sympy import TableForm >>> t = TableForm([[5, 7], [4, 2], [10, 3]], headings='automatic') >>> t | 1 2 -------- 1 | 5 7 2 | 4 2 3 | 10 3 >>> t.as_matrix() Matrix([ [ 5, 7], [ 4, 2], [10, 3]]) rr )r.r r:)r@r s r as_matrixzTableForm.as_matrixs( 0dkk""r+ct|Srr4)r@s ras_strzTableForm.as_strs 4yr+cddlm}||S)Nrlatexr])r@r^s ras_latexzTableForm.as_latexs T{r+c dg|jz}g}|jD]y}g}t|jD]L}t||}|jr|dk(rd}t |}|||kDr|||<|j |N|j |{|jdrR|jdD cgc] } t| c} |jd<td|jdD} |jdrog}t|jD]F}t|jd|}t |}|||kDr|||<|j |H||jd<g} d} t|j|D cgc]\} }| | |} } }|jdr5| jd| |j | jdddj| dz} g}|jdrf|jd}|jdrd g|z}| t|z}|j ||j d t |dz zdzt|D]\}}t|Dcgc]-\}}|j|d k7r|n|j!||/}}}|jdr:|jd|}|jd k7r|n|j! }|g|z}|j | t|zd j|d d Scc} wcc}} wcc}}w)z Returns the string representation of 'self'. Examples ======== >>> from sympy import TableForm >>> t = TableForm([[5, 7], [4, 2], [10, 3]]) >>> s = t.as_str() r0rc32K|]}t|ywrr)rxs rrz&TableForm._sympystr..s@c!f@rrc2d|dk(rdndt|dS)Nz%r-srZ)alignws r_alignz#TableForm._sympystr.._aligns! ",A r+| rfrerN)r8r:r5r4r?rr6r;r1zipr=insertr<jointupler2r")r@p column_widthslinesrnew_linerDrgrirc _head_width format_strrjrhrG first_linerErs r _sympystrzTableForm._sympystrsSdgg KK #DH477^ #QL##cAF}Q'''(M!$" # LL " # >>! 151B CAQ CDNN1 @dnnQ.?@@K >>! H477^ #q)!,-F}Q'''(M!$"  #!)DNN1    $**M:<85!fUA&< < >>!    a(8(8+!F G   a %XXj)D0  >>! q!A~~a D1H#eAh.J HHZ HHSC Oa/047 8 ' ,GAt8A$I041&&q)S0-*+,IAI~~a NN1%a(**c1QXXk*C!G HHZ%(* + ,wwqz#2Y!D(< Is;M M2Mc|jdrUg}t|jD],}|jt |jd|.||jd<g}|jdr@|jdDcgc] }t |c}|jd<|j g}|j |jddj|zdz}|jdrE|jd}|jdrdg|z}dj|dzd z}||z }|d z }t|jD]\}} g}t| D]\} }|jr|d vr|jd(|j| } | rEt| tr| ||| } | |j|} n| |z} |j| ~|j|} |jd | z|jdr|jd|g|z}|dj|dzd zz }|d z }|Scc}w)z> Returns the string representation of 'self'. rrz\begin{tabular}{rz} rfz & z \\rlz\hline )rraz$%s$z \end{tabular})r;r5r8r6r4r<r3r=rpr2r:r?r>r/r_print) r@printerrurDrrcrgrGrxrrEfvs r_latexzTableForm._latex=sJ >>! H477^ ;DNN1$5a$8 9: ;!)DNN1  >>! 151B CAQ CDNN1 **+J$**+ #((:"6 6 > >>! q!A~~a D1HA/$6J OA ! !A - /GAtA!$ )1##hHHSM((+!!\2aAJ9 'q 1AEHHQKq)AHHVaZ( ) ~~a ^^A&q)*Q. A'$. .A) /* G!DsIN) __name__ __module__ __qualname____doc__rLrSrVrXr[r_ryrr+rr r s32f'P&&#.IV1r+r N) sympy.core.containersrsympy.core.singletonrsympy.core.symbolrsympy.core.sympifyrtypesrr rr+rrs '"$+eer+