B .newfuncz ) r&r'r(r3r!AttributeErrorr$__doc__r__dict__update) r)r"r0kwargsr&r'r(r4docrr)r2r"r3r __call__Js8        z_Deprecate.__call__)NNN)r! __module__ __qualname__r6r*r;rrrr r%9s  r%cOs`|rR|d}|dd}d|kr.|d|d<d|krD|d|d<t|||St||SdS)a Issues a DeprecationWarning, adds warning to `old_name`'s docstring, rebinds ``old_name.__name__`` and returns the new function object. This function may also be used as a decorator. Parameters ---------- func : function The function to be deprecated. old_name : str, optional The name of the function to be deprecated. Default is None, in which case the name of `func` is used. new_name : str, optional The new name for the function. Default is None, in which case the deprecation message is that `old_name` is deprecated. If given, the deprecation message is that `old_name` is deprecated and `new_name` should be used instead. message : str, optional Additional explanation of the deprecation. Displayed in the docstring after the warning. Returns ------- old_func : function The deprecated function. Examples -------- Note that ``olduint`` returns a value after printing Deprecation Warning: >>> olduint = np.deprecate(np.uint) >>> olduint(6) /usr/lib/python2.5/site-packages/numpy/lib/utils.py:114: DeprecationWarning: uint32 is deprecated warnings.warn(str1, DeprecationWarning, stacklevel=2) 6 rNZnewnamer'Zoldnamer&)popr%)r0r9fnrrr r vs. cCs t|dS)N)r()r%)msgrrr rBc Cs|j}|dd}|d}|d}t|jj}|}}|dkrN||j|7}nJx@t||D]2\}} | dkr|||d| 7}qZ||d| 7}qZW||7}||fS)a1 Returns pointers to the end-points of an array. Parameters ---------- a : ndarray Input array. It must conform to the Python-side of the array interface. Returns ------- (low, high) : tuple of 2 integers The first integer is the first byte of the array, the second integer is just past the last byte of the array. If `a` is not contiguous it will not use every byte between the (`low`, `high`) values. Examples -------- >>> I = np.eye(2, dtype='f'); I.dtype dtype('float32') >>> low, high = np.byte_bounds(I) >>> high - low == I.size*I.itemsize True >>> I = np.eye(2, dtype='G'); I.dtype dtype('complex192') >>> low, high = np.byte_bounds(I) >>> high - low == I.size*I.itemsize True datarstridesshapeNr>)Z__array_interface__r dtypeitemsizesizezip) aZaiZa_dataZastridesZashapeZbytes_aZa_lowZa_highrFZstriderrr rs   c CsP|dkrtj}|j}g}i}x|D]}t||tr*||}t|}||krn|d||}d}n|||<|}d}dt t |j } t |j } | || | |jj|gq*Wd} d} d} d}xtt|D]|}||}| t|dkrt|d} | t|dkrt|d} | t|dkr8t|d} |dr|t|d7}qWt|dkrtd| }td| }td| }d |d |d |d f}t|d d t|d d xtt|D]t}||}td|dd |t|dd|dd |t|dd |dd |t|dd |dfqWtd|dS)a% Print the NumPy arrays in the given dictionary. If there is no dictionary passed in or `vardict` is None then returns NumPy arrays in the globals() dictionary (all NumPy arrays in the namespace). Parameters ---------- vardict : dict, optional A dictionary possibly containing ndarrays. Default is globals(). Returns ------- out : None Returns 'None'. Notes ----- Prints out the name, shape, bytes and type of all of the ndarrays present in `vardict`. Examples -------- >>> a = np.arange(10) >>> b = np.ones(20) >>> np.who() Name Shape Bytes Type =========================================================== a 10 40 int32 b 20 160 float64 Upper bound on total bytes = 200 >>> d = {'x': np.arange(2.0), 'y': np.arange(3.0), 'txt': 'Some str', ... 'idx':5} >>> np.who(d) Name Shape Bytes Type =========================================================== y 3 24 float64 x 2 16 float64 Upper bound on total bytes = 40 Nz (%s)rr>z x r, zName %s Shape %s Bytes %s Type r+=z%s %s %s %s %s %s %sz' Upper bound on total bytes = %d)sys _getframef_back f_globalskeys isinstanceridrmapstrrFnbytesappendrGr#rangelenintmaxprint)ZvardictframeZstacacher#varZidvnamestrZoriginalZshapestrZbytestrZmaxnameZmaxshapeZmaxbyteZ totalbyteskvalZsp1Zsp2Zsp3Zprvalrrr rs^,             c Cst|}|}|}d}||}xp|D]h}||kr6d} n|} |t|t| }||kr|dt|}|dd|d|}q$|| |}q$W|S)Nz, r>z, rNr,)r^split) r# argumentswidthZ firstwidthrfZnewstrZsepstrarglistZargumentZaddstrrrr _split_line\s  rmrcCst|ttg}|j|ji}|jg}|jg}xvt|dkr>P|d}xX|D]L}t||t j rR||j}||krR||j}| || ||||<qRWq0W||fS)Nr) __import__globalslocalsr!r7r^r?rVrWtypes ModuleTyper\)moduleZthedictZdictlistZ totraverseZthisdictxmodnameZmoddictrrr _makenamedictts"       rvc Csxd}d}dd}t|dt|}t|d|}|j}|jj}td||dtd|j|dtd ||dtd |j|dtd ||jj |dtd ||jj |dtd |jj |dtdt |j jj|f|dtdd|d|dkrtd|tj|f|dd} nH|dkr2td||f|dtjdk} ntd||f|dtjdk} td|| |dtd|j|ddS)aOProvide information about ndarray obj. Parameters ---------- obj : ndarray Must be ndarray, not checked. output Where printed output goes. Notes ----- Copied over from the numarray module prior to its removal. Adapted somewhat as only numpy is an option now. Called by info. rhcSs|S)Nr)rtrrr rBrCz_info.. __class__r!zclass: )filezshape: z strides: z itemsize: z aligned: z contiguous: z fortran: zdata pointer: %s%sz byteorder: rN)endrx)|rOz%s%s%sF>z%sbig%sZbigz %slittle%slittlez byteswap: ztype: %sN)getattrtyperErG byteorderrarFrHflagsZaligned contiguousZfortranhexZctypesZ_as_parameter_valuerR) objoutputZextraZticZbpclsZnmrEZendianZbyteswaprrr _infos8     rLc Csbddl}ddl}t|ds$t|dr,|j}nt|dr<|j}|dkrPttnt|trjt||dnt|t rTt dkrt |\a a d}g}xt D]}ylt ||} t | |krtd||dn6|t | td ||dt| td ||d|d 7}Wqtk rYqXqW|dkr@td ||dntd ||dn ||r|j} tt|} t| | |krt| | |} n| | } td| d|dt|||dn||rP|j} d} yZt|dr2tt|jj} | d} t| d kr2d| d | d <d| d d} Wn YnXt| | |krbt| | |} n| | } td| d|d||}|dkrt|drt||j|dnt|||d||}|gkr^td|dxd|D]\}|ddkrqt||d}|dk r2|||p*d\}}td||f|dqWnt j!ddkrt|t"j#rtd|j$j|dt|dt|dr|tt|j%j} | d} t| d krd| d | d <d| d d} nd} t|drd|j&} nd} t| | |kr"t| | |} n| | } td| d|d||j%}|dk rht||j%|dt|||dnt|||dn|'|r@|j} tt|j} | d} t| d krd| d | d <d| d d} nd} t| | |krt| | |} n| | } td| d|dt|||dnt|dr^t|||ddS)a Get help information for a function, class, or module. Parameters ---------- object : object or str, optional Input object or name to get information about. If `object` is a numpy object, its docstring is given. If it is a string, available modules are searched for matching objects. If None, information about `info` itself is returned. maxwidth : int, optional Printing width. output : file like object, optional File like object that the output is written to, default is ``stdout``. The object has to be opened in 'w' or 'a' mode. toplevel : str, optional Start search at this level. See Also -------- source, lookfor Notes ----- When used interactively with an object, ``np.info(obj)`` is equivalent to ``help(obj)`` on the Python prompt or ``obj?`` on the IPython prompt. Examples -------- >>> np.info(np.polyval) # doctest: +SKIP polyval(p, x) Evaluate the polynomial p at x. ... When using a string for `object` it is possible to get multiple results. >>> np.info('fft') # doctest: +SKIP *** Found in numpy *** Core FFT routines ... *** Found in numpy.fft *** fft(a, n=None, axis=-1) ... *** Repeat reference found in numpy.fft.fftpack *** *** Total of 3 references found. *** rNZ_ppimport_importer_ppimport_module_ppimport_attr)rz+ *** Repeat reference found in %s *** )rxz *** Found in %s ***-r>zHelp for %s not found.z+ *** Total of %d references found. ***rNr+z()r*z, (z Methods: _Nonez %s -- %srQzInstance of class: r;r#z%szr6)(pydocinspecthasattrrrrrWrrrZ _namedictrv _dictlistrXrar\KeyErrorZ isfunctionr!r r r^rmgetdocisclassr*__func__rirZ allmethodsr}ZsplitdocrR version_inforqZ InstanceTyperwr;r#Zismethod)objectZmaxwidthrZtoplevelrrZnumfoundZobjlistrerr#rjZargstrrlZdoc1methodsmethZthisobjZmethstrotherr:rrr rs3                                        cCsRddl}y,td|||dt|||dWntd|dYnXdS)a Print or write to a file the source code for a NumPy object. The source code is only returned for objects written in Python. Many functions and classes are defined in C and will therefore not return useful information. Parameters ---------- object : numpy object Input object. This can be any object (function, class, module, ...). output : file object, optional If `output` not supplied then source code is printed to screen (sys.stdout). File object must be created with either write 'w' or append 'a' modes. See Also -------- lookfor, info Examples -------- >>> np.source(np.interp) #doctest: +SKIP In file: /usr/lib/python2.6/dist-packages/numpy/lib/function_base.py def interp(x, xp, fp, left=None, right=None): """.... (full docstring printed)""" if isinstance(x, (float, int, number)): return compiled_interp([x], xp, fp, left, right).item() else: return compiled_interp(x, xp, fp, left, right) The source code is only returned for objects written in Python. >>> np.source(np.array) #doctest: +SKIP Not available for this object. rNz In file: %s )rxzNot available for this object.)rraZ getsourcefileZ getsource)rrrrrr rs (z[a-z0-9_]+\(.*[,=].*\)TFc sddl}t|||g}t|s0dSxZD]N\}\}} } | dkrRq:d} |} xD]} | | krdd} PqdW| r:||q:Wdddddfd d fd d }|j|d dd}|dt |g}x|dddD]}|\} } }dd| dD}y(|d }t |r@|d }Wnt k r\d}YnX|d||fqW|s|d|dk r|d|n4t |dkr|}|d|ntd|dS)a Do a keyword search on docstrings. A list of of objects that matched the search is displayed, sorted by relevance. All given keywords need to be found in the docstring for it to be returned as a result, but the order does not matter. Parameters ---------- what : str String containing words to look for. module : str or list, optional Name of module(s) whose docstrings to go through. import_modules : bool, optional Whether to import sub-modules in packages. Default is True. regenerate : bool, optional Whether to re-generate the docstring cache. Default is False. output : file-like, optional File-like object to write the output to. If omitted, use a pager. See Also -------- source, info Notes ----- Relevance is determined only roughly, by checking if the keywords occur in the function name, at the start of a docstring, etc. Examples -------- >>> np.lookfor('binary representation') Search results for 'binary representation' ------------------------------------------ numpy.binary_repr Return the binary representation of the input number as a string. numpy.core.setup_common.long_double_representation Given a binary dump as given by GNU od -b, look for long double numpy.base_repr Return a string representation of a number in the given base system. ... rN)rsrTFii)r"classrsrcsd}d|ddd|tfddD7}|tfddD7}|t d7}||d7}|d  d 7}|t| d d 7}|S) Nrr+rQcsg|]}|krdqS)r).0w) first_docrr sz.lookfor..relevance..csg|]}|krdqS)r)rr)r#rr rsrPi.rMdi) rlowerstriprisumr^getcountr`)r#Zdocstrkindindexr)kind_relevancewhats)rr#r relevances zlookfor..relevancecs|f|S)Nr)rK)rcrrr relevance_valuesz lookfor..relevance_value)keyzSearch results for '%s'rNrcSsg|]}|r|qSr)r)rlinerrr r)szlookfor..r+r>rhz %s %szNothing found.rM)r_lookfor_generate_cacherZrriitemsr\sortrr^r_function_signature_research IndexErrorwriteZgetpagerra)Zwhatrsimport_modules regeneraterrfoundr#Z docstringrrokr:rrsZ help_textZixZdoclinesrZpagerr)rcrrrr rsT.         c Csddl}tjddkr$ddlm}n ddlm}|dkrt | D] \}}| %d| |f|fqfWnt| drd} y|'| }Wnt"k rd}YnX|dk r|| |f|| <qW|S)a Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate : bool Re-generate the docstring cache Returns ------- cache : dict {obj_full_name: (docstring, kind, index), ...} Docstring cache for the module, either cached one (regenerate=False) or newly generated. rNrQ)StringIOrTr>rrs__path__z __init__.pyz.pyr*z%s.%sr!r<rrr;r")(rrRriorrWrZrn ImportErrormoduleslisttupler8rrX_lookfor_cachesr!r?Zismodule__all__r5rrrlistdirrrisfileendswithstdoutstderr BaseException _getmembersr} NameError startswithr r\rr)rsrrrrrcmodseenrstackr#itemrZ_allZpthZmod_pathZthis_pyZinit_pyZ to_importZ old_stdoutZ old_stderrnvZ item_nameZmod_namer:rrr rAs                           rcsFddl}y|}Wn*tk r@fddtD}YnX|S)Nrcs$g|]}t|r|t|fqSr)rr})rrt)rrr rsz_getmembers..)rZ getmembers Exceptiondir)rrmembersr)rr rs rc@sxeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZdS)SafeEvalz Object to evaluate constant string expressions. This includes strings with lists, dicts and tuples using the abstract syntax tree created by ``compiler.parse``. .. deprecated:: 1.10.0 See Also -------- safe_eval cCstjdtdddS)Nz3SafeEval is deprecated in 1.10 and will be removed.r,)r-)r3r.r/)r)rrr r*szSafeEval.__init__cCs"|j}t|d|j|j}||S)Nvisit)rwr}r!default)r)noderrrrr rszSafeEval.visitcCstd|jdS)Nz Unsupported source construct: %s) SyntaxErrorrw)r)rrrr rszSafeEval.defaultcCs ||jS)N)rZbody)r)rrrr visitExpressionszSafeEval.visitExpressioncCs|jS)N)r)r)rrrr visitNumszSafeEval.visitNumcCs|jS)N)r)r)rrrr visitStrszSafeEval.visitStrcCs|jS)N)r)r)rrrr visitBytes szSafeEval.visitBytesc s tfddt|j|jDS)Ncs$g|]\}}||fqSr)r)rrfr)r)rr rsz&SafeEval.visitDict..)dictrJrVvalues)r)rkwr)r)r visitDict s zSafeEval.visitDictcstfdd|jDS)Ncsg|]}|qSr)r)ri)r)rr rsz'SafeEval.visitTuple..)relts)r)rr)r)r visitTupleszSafeEval.visitTuplecsfdd|jDS)Ncsg|]}|qSr)r)rr)r)rr rsz&SafeEval.visitList..)r)r)rr)r)r visitListszSafeEval.visitListcCsRddl}t|j|jr$||j St|j|jr@||j Std|jdS)NrzUnknown unary op: %r)astrWopZUAddrZoperandZUSubr)r)rrrrr visitUnaryOps zSafeEval.visitUnaryOpcCs<|jdkrdS|jdkrdS|jdkr*dStd|jdS)NFalseFTrueTrzUnknown name: %s)rXr)r)rrrr visitName s   zSafeEval.visitNamecCs|jS)N)r)r)rrrr visitNameConstant*szSafeEval.visitNameConstantN)r!r<r=r6r*rrrrrrrrrrrrrrrr rs   rcCsddl}||S)a Protected string evaluation. Evaluate a string containing a Python literal expression without allowing the execution of arbitrary non-literal code. Parameters ---------- source : str The string to evaluate. Returns ------- obj : object The result of evaluating `source`. Raises ------ SyntaxError If the code has invalid Python syntax, or if it contains non-literal code. Examples -------- >>> np.safe_eval('1') 1 >>> np.safe_eval('[1, 2, 3]') [1, 2, 3] >>> np.safe_eval('{"foo": ("bar", 10.0)}') {'foo': ('bar', 10.0)} >>> np.safe_eval('import os') Traceback (most recent call last): ... SyntaxError: invalid syntax >>> np.safe_eval('open("/home/user/.ssh/id_dsa").read()') Traceback (most recent call last): ... SyntaxError: Unsupported source construct: compiler.ast.CallFunc rN)rZ literal_eval)rrrrr r.s,cCs|jdkr|St|||j}t|d}tj|rB|d}|jdkr|dkrtj dt dd|dk r|j tj |d <|}q|j tj }n>t|dkrtj d d t|t ddtj ||<|S) aj Utility function to check median result from data for NaN values at the end and return NaN in that case. Input result can also be a MaskedArray. Parameters ---------- data : array Input data to median function result : Array or MaskedArray Result of median function axis : {int, sequence of int, None}, optional Axis or axes along which the median was computed. out : ndarray, optional Output array in which to place the result. Returns ------- median : scalar or ndarray Median or NaN in axes which contained NaN in the input. r).rFTz#Invalid value encountered in medianrQ)r-N.z'Invalid value encountered in median forz %d results)rInpZrollaxisndimZisnanZmaZ isMaskedArrayZfilledr3r.RuntimeWarningrGr~nanZ count_nonzeroZravel)rDresultZaxisoutrrrr _median_nancheck_s(       r)N)r)NTFN)1Z __future__rrrrrRrqrer3Znumpy.core.numerictypesrrrrrr r rrZ numpy.compatr r rrr$rr%r rrrrmrrrvrrrrrcompileIrrrrrrrrrrr sJ  ==9 i 3N3  I1