B Gd2d3d3e?Z@d4d5ZAGd6d7d7e?ZBGd8d9d9e?ZCGd:d;d;e?ZDGdd?d?e?ZFGd@dAdAe?ZGGdBdCdCe?ZHGdDdEdEe?ZIdS)IzXArray printing function $Id: arrayprint.py,v 1.9 2005/09/13 13:58:44 teoliphant Exp $ )divisionabsolute_importprint_function array2stringset_printoptionsget_printoptionsZrestructuredtextN) get_ident) numerictypes)maximumminimumabsolute not_equalisnanisinf)arrayformat_longfloatdatetime_as_string datetime_datadtype)ravel)asarraycCs||S)N)xyrrH/opt/alt/python37/lib64/python3.7/site-packages/numpy/core/arrayprint.pyproduct-sriFKnaninfcCs`|dk r |a|dk r|a|dk r$|a|dk r0|a|dk r@| a|dk rL|a|dk rX|a|adS)a 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 - 'numpystr' : types `numpy.string_` and `numpy.unicode_` - 'object' : `np.object_` arrays - '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) _line_width_summaryThreshold_summaryEdgeItems_float_output_precision_float_output_suppress_small_nan_str_inf_str _formatter) precision threshold edgeitems linewidthsuppressnanstrinfstr formatterrrrr;snc Cstttttttttd}|S)a  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/r0r1) dictr%r#r$r"r&r'r(r))drrrrscsddlm}jdkrNtdtkrH|dtt df}qԈ}ntdtkrfddttttD}|fddttttddDnfd dtdtD}|t |}|S) Nr )numericcsg|]}t|qSr)_leading_trailing).0i)arr sz%_leading_trailing..csg|]}t| qSr)r6)r7r8)r9rrr:srcsg|]}t|qSr)r6)r7r8)r9rrr:s) r4ndimlenr$Z concatenaterangeminextendtuple)r9_ncblr)r9rr6s   r6cCs|rdSdSdS)Nz TrueFalser)rrrr_boolFormattersrGcCs t|tkrd}nd}||S)z@ Object arrays containing lists should be printed unambiguously z list({!r})z{!r})typelistformat)oZfmtrrr_object_formats rLcCst|S)N)repr)rrrr repr_formatsrNc sddfddfddfddfddfddfddfd dd dd dd dd }dd}dk rfddD}d|krx |D]}|d||<qWd|krxdD]}|d||<qWd|kr xdD]}|d||<qWd|kr6xdD]}|d||<qWd|kr`xdD]}|d||<qFWx,|D] }||krj||||<qjW|S)NcSstS)N)rGrrrrz!_get_formatdict..cstS)N) IntegerFormatr)datarrrOrPcs tS)N) FloatFormatr)rRr*suppress_smallrrrOrPcstS)N)LongFloatFormatr)r*rrrOrPcs tS)N) ComplexFormatr)rRr*rTrrrOscstS)N)LongComplexFormatr)r*rrrOrPcstS)N)DatetimeFormatr)rRrrrO rPcstS)N)TimedeltaFormatr)rRrrrO rPcSstS)N)rLrrrrrO rPcSstS)N)rNrrrrrO rPcSstS)N)strrrrrrO rP) boolintfloat longfloat complexfloatlongcomplexfloatdatetime timedeltaobjectnumpystrrZcs fddS)NcsS)Nrr)rrrrOrPz3_get_formatdict..indirect..r)rr)rrindirectsz!_get_formatdict..indirectcsg|]}|dk r|qS)Nr)r7k)r1rrr:sz#_get_formatdict..allZint_kind)r\Z float_kind)r]r^Z complex_kind)r_r`Zstr_kind)rdrZ)keys)rRr*rTr1 formatdictreZfkeyskeyr)rRr1r*rTr_get_formatdictsB               rkc Csz|j}|jdk rfg}xH|jD]>}||}tt||||}||jdkrPt|}||qWt|S|j } t ||||} t | t j r| dSt | t jrt | t jr| dS| dSnt | t jrt | t jr| dS| dSnt | t jrt | t jr| dS| d SnXt | t jt jfr<| d St | t jrT| d St | t jrl| d S| d SdS) z; find the right formatting function for the dtype_ Nrr[rbr\r^r]r`r_rdrarc)rfieldsnames_get_format_functionrshapeSubArrayFormatappendStructureFormatrHrk issubclass_ntZbool_ZintegerZ timedelta64Zfloatingr^ZcomplexfloatingZ clongfloatZunicode_Zstring_Z datetime64Zobject_) rRr*rTr1Zdtype_format_functionsZ field_nameZ field_valuesformat_functionZdtypeobjrirrrrn+sD                 rn r<c Csn|jtkrd}t|}nd}tt|}t||||} d} | dt|7} t|| |j|| |t |dd} | S)Nz..., r<rwr;) sizer#r6rrrnr> _formatArrayr=r$) r9max_line_widthr*rT separatorprefixr1summary_insertrRrvnext_line_prefixlstrrr _array2stringWs    r...csfdd}|S)a  Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs Decorates a function such that if it calls itself with the same first argument, it returns `fillvalue` instead of recursing. Largely copied from reprlib.recursive_repr cs$ttfdd}|S)Nc sFt|tf}|krS|z|f||S|XdS)N)idr adddiscard)selfargskwargsrj)f fillvalue repr_runningrrwrapper}s z>_recursive_guard..decorating_function..wrapper)set functoolswraps)rr)r)rrrdecorating_functionzs z-_recursive_guard..decorating_functionr)rrr)rr_recursive_guardps rc Cs|dkr t}|dkrt}|dkr$t}|dkr0t}|jdkr|}|jjdk rzt|g|jd} t | |||} | | d} q||} n.t t |jdkrd} nt |||||||d} | S)a Return a string representation of an array. Parameters ---------- a : ndarray Input array. max_line_width : int, optional The maximum number of columns the string should span. Newline characters splits the string appropriately after array elements. precision : int, optional Floating point precision. Default is the current printing precision (usually 8), which can be altered using `set_printoptions`. suppress_small : bool, optional Represent very small numbers as zero. A number is "very small" if it is smaller than the current printing precision. separator : str, optional Inserted between elements. prefix : str, optional An array is typically printed as:: 'prefix(' + array2string(a) + ')' The length of the prefix string is used to align the output correctly. style : function, optional A function that accepts an ndarray and returns a string. Used only when the shape of `a` is equal to ``()``, i.e. for 0-D arrays. 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 - 'numpystr' : 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' Returns ------- array_str : str String representation of the array. Raises ------ TypeError if a callable in `formatter` does not return a string. See Also -------- array_str, array_repr, set_printoptions, get_printoptions Notes ----- If a formatter is specified for a certain type, the `precision` keyword is ignored for that type. This is a very flexible function; `array_repr` and `array_str` are using `array2string` internally so keywords with the same name should work identically in all three functions. Examples -------- >>> 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]' Nr)rrz[])r1)r"r%r&r)roitemrrlrrnrreducerr) r9rzr*rTr{r|Zstyler1rarrrvrrrrrs*b      cCs@t|t||kr0||d7}|}||7}||fS)N )r>rstrip)slineword max_line_lenr~rrr _extendLines rc Csv|dkrtd|r2d|t|kr2|}|} |} nd}t|} d} |dkr"d} |} x4t|D](} ||| |}t| | |||\} } q^W| rt| | | ||\} } x:t| ddD]*} ||| |}t| | |||\} } qW||d}t| | |||\} } | | d7} d| t|d } nPd} |}xlt|D]`} | dkrN| |7} | t|| ||d|d ||||7} | |d t|dd} q8W| r| || d 7} xxt| ddD]h} |s| | kr| |7} | t|| ||d|d ||||7} | |d t|dd} qW|s<| dkrD| |7} | t|d||d|d ||||d7} | S) zgformatArray is designed for two modes of operation: 1. Full output 2. Summarized output rzrank shouldn't be zero.r5r<r r;z] [Nrwr) ValueErrorr>r?rrrymax)r9rvZrankrr~r{Z edge_itemsr}Z leading_itemsZtrailing_itemsZsummary_insert1rrr8rseprrrrys`      ( ( ryc@s(eZdZd ddZddZd ddZd S) rSFc CsP||_||_||_d|_d|_d|_y||Wnttfk rJYnXdS)NFr) r*rTsign exp_formatlarge_exponent max_str_len fillFormat TypeErrorNotImplementedError)rrRr*rTrrrr__init__[szFloatFormat.__init__c sddlm}|jddt|t|B}t|d|@}t||}t|dkr^d}d}nBt |}t |}|dkrd_ j s|d ks||d krd_ WdQRXj rd|kod knp|d k_d j_jrjd7_jrdnddjjfndjft|rLtfdd|D}nd}tj|}ttt||d_||rtjttttd_jrdnddj|fdjf__dS)Nr )r4ignore)rgrggחATg-C6?g@@g>N}a+g}Ô%ITrz%+%z%d.%dez%%.%dfcsg|]}t|jqSr)_digitsr*)r7r)rJrrrr:sz*FloatFormat.fillFormat..r5z%#+z%#z%d.%dfz%%%ds)r<r4errstaterrrrcompressr>r rr rrTrr*rrrr@rZr\anyr'r( special_fmtrJ) rrRrCZspecialZvalidZnon_zeroZmax_valZmin_valr*r)rJrrrisR     "      zFloatFormat.fillFormatTc Cs:ddlm}|jddvt|rF|jr8|jdtfS|jtfSnDt|r|dkrz|jrl|jdtfS|jtfSn|jdtfSWdQRX|j |}|j r|d}|dks|dkr|dd d |d d}n\|j r|dd kr6d |dd|d d}n(|r6| d }|d t |t |}|S) Nr )r4r)Zinvalid+r-0rw)r<r4rrrrr'rr(rJrrrr>)rr strip_zerosrCrZexpsignzrrr__call__s0   zFloatFormat.__call__N)F)T)__name__ __module__ __qualname__rrrrrrrrSZs 3rScCs6|dkr.||}|d}|t|t|SdSdS)Nrr)rr>)rr*rJrrrrrrs  rc@seZdZddZddZdS)rQc CslyrZr rr rJrrr)rrRrrrrrszIntegerFormat.__init__cCs.t|krtkr"nn |j|Sd|SdS)Nz%s)_MININT_MAXINTrJ)rrrrrrs zIntegerFormat.__call__N)rrrrrrrrrrQs rQc@seZdZdddZddZdS)rUFcCs||_||_dS)N)r*r)rr*rrrrrszLongFloatFormat.__init__cCst|r |jrdtSdtSnnt|rR|dkrH|jr>dtSdtSqdtSn<|dkr|jrpdt||jSdt||jSn t||jSdS)Nrrwrr)rrr'rr(rr*)rrrrrrs   zLongFloatFormat.__call__N)F)rrrrrrrrrrUs rUc@seZdZddZddZdS)rWcCst||_t|dd|_dS)NT)r)rU real_format imag_format)rr*rrrrs zLongComplexFormat.__init__cCs$||j}||j}||dS)Nj)rrealrimag)rrrr8rrrrs  zLongComplexFormat.__call__N)rrrrrrrrrrWsrWc@seZdZddZddZdS)rVcCs(t|j|||_t|j||dd|_dS)NT)r)rSrrrr)rrr*rTrrrrs zComplexFormat.__init__cCs`|j|jdd}|j|jdd}|jjsP|d}|ddt|t|}n|d}||S)NF)rrrrw)rrrrrrr>)rrrr8rrrrr s zComplexFormat.__call__N)rrrrrrrrrrVsrVc@seZdZdddZddZdS)rXN same_kindcCsJ|dkr(|jjdkr$t|jd}nd}|dkr4d}||_||_||_dS)NMrrZnaive)rkindrtimezoneunitcasting)rrrrrrrrrs zDatetimeFormat.__init__cCsdt||j|j|jdS)Nz'%s')rrr)rrrr)rrrrrr$szDatetimeFormat.__call__)NNr)rrrrrrrrrrXs rXc@seZdZddZddZdS)rYcCs|jjdkrtdg|jdd}t|jjd}||}|t|||}t|dkrtttt |ttt |}nd}t|t|krt|d}dt|d|_ d ||_dS) NmZNaT)rri8rr3z'NaT')rrr byteorderviewrr>rrZr rr rJrjust_nat)rrRZ nat_valueZ int_dtypeZint_viewvrrrrr+s    zTimedeltaFormat.__init__cCs2|dd|dkr|jS|j|dSdS)Nr r)rrrJZastype)rrrrrr=szTimedeltaFormat.__call__N)rrrrrrrrrrY*srYc@seZdZddZddZdS)rpcCs ||_dS)N)rv)rrvrrrrFszSubArrayFormat.__init__csJ|jdkr*ddfdd|DdSddfdd|DdS)Nr rz, c3s|]}|VqdS)N)rv)r7r9)rrr Ksz*SubArrayFormat.__call__..]c3s|]}|VqdS)N)r)r7r9)rrrrLs)r=join)rrr)rrrIs  zSubArrayFormat.__call__N)rrrrrrrrrrpEsrpc@seZdZddZddZdS)rrcCs||_t||_dS)N)rur> num_fields)rrurrrrPszStructureFormat.__init__cCsTd}x(t||jD]\}}|||d7}qWd|jkrD|ddn |dddS)N(z, r rr;))ziprur)rrrZfieldrvrrrrTszStructureFormat.__call__N)rrrrrrrrrrrOsrr)NNNNNNNN)rwr<N)r)J__doc__Z __future__rrr__all__Z __docformat__sysr version_info_threadr ImportErrorZ _dummy_threadZthreadZ dummy_threadr<r rtZumathr r rrrrZ multiarrayrrrrrZ fromnumericrr4rmaxsizerrZmaxintrr$r#r%r&r"r'r(r)rrr6rGrLrNrkrnrrrMrrryrcrSrrQrUrWrVrXrYrprrrrrrs~        {#+,  }Cd