9Zc @`sdZddlmZmZmZdddgZdZddlZddlm Z d d l m Z d d l mZmZmZmZmZmZd d lmZmZmZmZd d lmZd dlmZejddkrejZej d Z nej!Zej! d Z dZ"da#da$da%e&a'da(da)da*da,dddddddddZ-dZ.dZ/dZ0dZ1ddddZ2dZ3ddddde4ddZ5d Z6d!Z7d"e8fd#YZ9d$Z:d%e8fd&YZ;d'e8fd(YZ<d)e8fd*YZ=d+e8fd,YZ>d-e8fd.YZ?d/e8fd0YZ@dS(1sXArray printing function $Id: arrayprint.py,v 1.9 2005/09/13 13:58:44 teoliphant Exp $ i(tdivisiontabsolute_importtprint_functiont array2stringtset_printoptionstget_printoptionstrestructuredtextN(treducei(t numerictypes(tmaximumtminimumtabsolutet not_equaltisnantisinf(tarraytformat_longfloattdatetime_as_stringt datetime_data(travel(tasarrayicC`s||S(N((txty((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pytproduct"siiiKtnantinfcC`s|dk r|an|dk r*|an|dk r?|an|dk rT|an|dk rk| an|dk r|an|dk r|an|adS(sv Set printing options. These options determine the way floating point numbers, arrays and other NumPy objects are displayed. Parameters ---------- precision : int, optional Number of digits of precision for floating point output (default 8). threshold : int, optional Total number of array elements which trigger summarization rather than full repr (default 1000). edgeitems : int, optional Number of array items in summary at beginning and end of each dimension (default 3). linewidth : int, optional The number of characters per line for the purpose of inserting line breaks (default 75). suppress : bool, optional Whether or not suppress printing of small floating point values using scientific notation (default False). nanstr : str, optional String representation of floating point not-a-number (default nan). infstr : str, optional String representation of floating point infinity (default inf). formatter : dict of callables, optional If not None, the keys should indicate the type(s) that the respective formatting function applies to. Callables should return a string. Types that are not specified (by their corresponding keys) are handled by the default formatters. Individual types for which a formatter can be set are:: - 'bool' - 'int' - 'timedelta' : a `numpy.timedelta64` - 'datetime' : a `numpy.datetime64` - 'float' - 'longfloat' : 128-bit floats - 'complexfloat' - 'longcomplexfloat' : composed of two 128-bit floats - 'numpy_str' : types `numpy.string_` and `numpy.unicode_` - 'str' : all other strings Other keys that can be used to set a group of types at once are:: - 'all' : sets all types - 'int_kind' : sets 'int' - 'float_kind' : sets 'float' and 'longfloat' - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' - 'str_kind' : sets 'str' and 'numpystr' See Also -------- get_printoptions, set_string_function, array2string Notes ----- `formatter` is always reset with a call to `set_printoptions`. Examples -------- Floating point precision can be set: >>> np.set_printoptions(precision=4) >>> print(np.array([1.123456789])) [ 1.1235] Long arrays can be summarised: >>> np.set_printoptions(threshold=5) >>> print(np.arange(10)) [0 1 2 ..., 7 8 9] Small results can be suppressed: >>> eps = np.finfo(float).eps >>> x = np.arange(4.) >>> x**2 - (x + eps)**2 array([ -4.9304e-32, -4.4409e-16, 0.0000e+00, 0.0000e+00]) >>> np.set_printoptions(suppress=True) >>> x**2 - (x + eps)**2 array([-0., -0., 0., 0.]) A custom formatter can be used to display array elements as desired: >>> np.set_printoptions(formatter={'all':lambda x: 'int: '+str(-x)}) >>> x = np.arange(3) >>> x array([int: 0, int: -1, int: -2]) >>> np.set_printoptions() # formatter gets reset >>> x array([0, 1, 2]) To put back the default options, you can use: >>> np.set_printoptions(edgeitems=3,infstr='inf', ... linewidth=75, nanstr='nan', precision=8, ... suppress=False, threshold=1000, formatter=None) N( tNonet _line_widtht_summaryThresholdt_summaryEdgeItemst_float_output_precisiont_float_output_suppress_smallt_nan_strt_inf_strt _formatter(t precisiont thresholdt edgeitemst linewidthtsuppresstnanstrtinfstrt formatter((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyR0sm              cC`s=tdtdtdtdtdtdtdtdt}|S( s  Return the current print options. Returns ------- print_opts : dict Dictionary of current print options with keys - precision : int - threshold : int - edgeitems : int - linewidth : int - suppress : bool - nanstr : str - infstr : str - formatter : dict of callables For a full description of these options, see `set_printoptions`. See Also -------- set_printoptions, set_string_function R#R$R%R&R'R(R)R*( tdictRRRRRR R!R"(td((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs  cC`sAddlm}|jdkr_t|dtkrV|j|t |t f}q=|}nt|dtkrgttt|tD]}t||^q}|j gttt|tddD]}t|| ^qn2gtdt|D]}t||^q }|jt |}|S(Ni(tnumericiii( tR-tndimtlenRt concatenatetrangetmint_leading_trailingtextendttuple(tat_nctbtitl((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyR4s  2 =2cC`s|r dSdSdS(Ns TruetFalse((R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyt_boolFormatterscC`s t|S(N(trepr(R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyt repr_formatst R.c C`s|dkrt}n|dkr*t}n|dkr?t}n|dkrTt}n|jtkrxd}t|}nd}tt |}i t d6t |d6t |||d6t |d6t|||d6t|d6t|d 6t|d 6td 6td 6} |dk rg|jD]} || dk r+| ^q+} d | krx%| jD]} |d | | >> x = np.array([1e-16,1,2,3]) >>> print(np.array2string(x, precision=2, separator=',', ... suppress_small=True)) [ 0., 1., 2., 3.] >>> x = np.arange(3.) >>> np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x}) '[0.00 1.00 2.00]' >>> x = np.arange(3) >>> np.array2string(x, formatter={'int':lambda x: hex(x)}) '[0x0L 0x1L 0x2L]' is[]R*((RgtitemRwR6RzRRRv( R7RhR#RiRjRktstyleR*RRu((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRTsa  cC`sYt|jt|j|krE||jd7}|}n||7}||fS(Ns (R0trstrip(tstlinetwordt max_line_lenRt((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyt _extendLines (  c C`sd|dkr@|j}t|tr6t|}nt|S|rqd|t|krq|} |} |} nd} t|} d} |dkrd} |} xFt| D]8}||||}t| | |||\} } qW| rt| | | ||\} } nxMt| ddD]9}||| |}t| | |||\} } q$W||d}t| | |||\} } | | d7} d| t|} nd} |j}xt| D]{}|dkr| |7} n| t ||||d|d||||7} | j|jd t |dd} qW| rm| || d 7} nxt| ddD]}| s|| kr| |7} n| t || ||d|d||||7} | j|jd t |dd} qW| s| dkr%| |7} n| t |d||d|d||||jd7} | S( sgformatArray is designed for two modes of operation: 1. Full output 2. Summarized output iiR.iis] t[R@s ( R~RwR6RzRJR0R2RRRftmax(R7RstrankRRtRjt edge_itemsRlR|t leading_itemsttrailing_itemstsummary_insert1RRR:Rtsep((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRfsf      "!"     /   /  RRcB`s)eZedZdZedZRS(cC`se||_||_||_t|_t|_d|_y|j|Wntt fk r`nXdS(Ni( R#RitsignR<t exp_formattlarge_exponentt max_str_lent fillFormatt TypeErrortNotImplementedError(tselfRmR#RiR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyt__init__s      c C`sddlm}|jddt|t|B}t|d|@}t|j|}t|dkrd}d}nht j |}t j |}|dkrt |_ n|j r|dks||d krt |_ nWdQX|j rd|kod knp|d k|_d |j|_|jrP|jd7_n|jrbd }nd}|d|j|jf}nd|jf}t|rtg|D]} t| |j|^q} nd} t|j| } ttt|| d|_|j|rGt|jttttd|_n|jrYd}nd}|d|j| f}d|jf|_||_dS(Ni(R-RKtignoreiggחAg-C6?g@@g>N}a+g}Ô%ITis%+t%s%d.%des%%.%dfis%#+s%#s%d.%dfs%%%ds(R.R-terrstateR RR R tcompressR0R RR tTrueRRiRR#RRRt_digitsR3RJRBtanyR R!t special_fmttformat( RRmR8tspecialtvalidtnon_zerotmax_valtmin_valRRR#((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRsR    +    +#    cC`sddlm}|jddt|r[|jrJ|jdtfS|jtfSnYt|r|dkr|jr|jdtfS|jtfSq|jdtfSnWdQX|j |}|j r|d}|dks|dkr||dd !d |d }q|nk|j rF|dd kr|d |d |d }q|n6|r||j d }|d t |t |}n|S( Ni(R-tinvalidRt+it-iit0R@(R.R-RR RRR RR!RRRRR0(RRt strip_zerosR8Rtexpsigntz((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyt__call__Rs0         !(t__name__t __module__R<RRRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRRs  3cC`s1||}|jd}|t|t|S(NR(RR0(RR#RRR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRts RQcB`seZdZdZRS(cC`syTttttj|tttj|}dt|d|_Wn'ttfk rmnt k r}nXdS(NRR,( RR0RJR RR RRRt ValueError(RRmR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyR{s cC`s3t|kotknr'|j|Sd|SdS(Ns%s(t_MININTt_MAXINTR(RR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs (RRRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRQzs RScB`seZedZdZRS(cC`s||_||_dS(N(R#R(RR#R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs cC`st|r(|jrdtSdtSnt|rg|dkr\|jrQdtSdtSqdtSnP|dkr|jrdt||jSdt||jSnt||jSdS(NRR@iR(R RR RR!RR#(RR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs          (RRR<RR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRSs RUcB`seZdZdZRS(cC`s(t||_t|dt|_dS(NR(RSt real_formatRt imag_format(RR#((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRscC`s0|j|j}|j|j}||dS(Ntj(RtrealRtimag(RRtrR:((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs(RRRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRUs RTcB`seZdZdZRS(cC`s:t|j|||_t|j||dt|_dS(NR(RRRRRRR(RRR#Ri((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRscC`s|j|jdt}|j|jdt}|jjsp|jd}|ddt|t|}n |d}||S(NRRRR@(RRR<RRRRR0(RRRR:R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs % (RRRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRTs RVcB`s#eZddddZdZRS(t same_kindcC`sq|dkr=|jjdkr4t|jd}q=d}n|dkrRd}n||_||_||_dS(NtMiRtnaive(RRYtkindRttimezonetunittcasting(RRRRR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs      c C`s)dt|d|jd|jd|jS(Ns'%s'RRR(RRRR(RR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs   N(RRRRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRVsRWcB`seZdZdZRS(cC`s|jjdkrtdgd|jd}|t||jd}t|dkrttttj |ttt j |}nd}t|t|krt|d}ndt|d|_ d j ||_ ndS( NtmtNaTRYiti8iRR,s'NaT'(RYRRR tviewR0RRJR RR Rtrjustt_nat(RRmt nat_valuetvR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs!cC`s/|d|kr|jS|j|jdSdS(NiR(RRtastype(RR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRs(RRRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyRWs (At__doc__t __future__RRRt__all__t __docformat__tsyst functoolsRR.RR\tumathR R R R R Rt multiarrayRRRRt fromnumericRR-Rt version_infotmaxsizeRRtmaxintRRRRR<RRR R!RR"RRR4R=R?RvRzR>RRRftobjectRRRRQRSRURTRVRW(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/arrayprint.pyts` ."     z #   Z  l  Fd