2[c*@`sddlmZmZmZyddljZWnek rNddlZnXddl Z ddl Z ddl Z ddl Z ddl ZddljjZddlmZmZmZmZddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCddlDmEZEmFZFddlGmHZHd d lImJZJdd lKmLZLmMZMmNZNmOZOmPZPmQZRmSZTdd l-mUZVdd lWmXZXddlYmZZZe j[ddkre\Z]ddl^Z_n ddl_Z_ddl`maZambZbdddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:g*Zcd dd fd;Zdeed<Zfd=Zgeeeeehd>Zieeeed?Zjd@ZkddAZldBdCZmdDZnd dEdFZoeeeeeedGZQddHZpe.dEdIZqdJZrdKdLZseJdMZtdNZudOZveeewdPZxdQZydRjzeyZ{dSjze{Z|dTjze|Z}dUjze}Z~dVZdWZdXZdYZdZZd!efd[YZeeeweheeeeeed\Zeeewejejd]Zd^Zd_Zd`ZdaZdbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dgZdddddddddddddddddddddddddgZdZdZdZdZdZdZdZdZeeeeehehdZeeeeehdZeeeeehdehdZeeeeehdehdZeeeeehdehdZdZeeeeehdehdZeeddEdZdZdZeedZeedZeedZdS(i(tdivisiontabsolute_importtprint_functionN(tlinspacet atleast_1dt atleast_2dt transpose(tonestzerostaranget concatenatetarraytasarrayt asanyarraytemptyt empty_liketndarraytaroundtfloortceilttaketdottwheretintptintegertisscalartabsolutet AxisError(tpitmultiplytaddtarctan2t frompyfunctcost less_equaltsqrttsintmodtexptlog10t not_equaltsubtract(traveltnonzerotsortt partitiontmeantanytsum(t typecodestnumber(tdiagi(t deprecate(t_insertt add_docstringtdigitizetbincounttnormalize_axis_indextinterptinterp_complex(t_add_newdoc_ufunc(tlong(t basestringi(t histogramt histogramddtselectt piecewiset trim_zerostcopytiterablet percentiletdifftgradienttangletunwrapt sort_complextdisptfliptrot90textracttplacet vectorizetasarray_chkfinitetaverageR8R7tcovtcorrcoeftmsorttmediantsincthammingthanningtbartletttblackmantkaiserttrapzti0t add_newdocR6tmeshgridtdeletetinserttappendR:tadd_newdoc_ufunctquantilecC`st|}t|dkr-tdnt|}|d|dksnt|d|d|jkr}tdn|d|jks|d|j ks|d|jks|d|j krtdj||jn|d;}|dkr|S|dkr.tt||d|dStd|j}||d||d||d<||d<|dkrt t||d|Stt |||dSdS( s Rotate an array by 90 degrees in the plane specified by axes. Rotation direction is from the first towards the second axis. Parameters ---------- m : array_like Array of two or more dimensions. k : integer Number of times the array is rotated by 90 degrees. axes: (2,) array_like The array is rotated in the plane defined by the axes. Axes must be different. .. versionadded:: 1.12.0 Returns ------- y : ndarray A rotated view of `m`. See Also -------- flip : Reverse the order of elements in an array along the given axis. fliplr : Flip an array horizontally. flipud : Flip an array vertically. Notes ----- rot90(m, k=1, axes=(1,0)) is the reverse of rot90(m, k=1, axes=(0,1)) rot90(m, k=1, axes=(1,0)) is equivalent to rot90(m, k=-1, axes=(0,1)) Examples -------- >>> m = np.array([[1,2],[3,4]], int) >>> m array([[1, 2], [3, 4]]) >>> np.rot90(m) array([[2, 4], [1, 3]]) >>> np.rot90(m, 2) array([[4, 3], [2, 1]]) >>> m = np.arange(8).reshape((2,2,2)) >>> np.rot90(m, 1, (1,2)) array([[[1, 3], [0, 2]], [[5, 7], [4, 6]]]) islen(axes) must be 2.iisAxes must be different.s*Axes={} out of range for array of ndim={}.iN( ttupletlent ValueErrorR RtndimtformatRMR R(tmtktaxest axes_list((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRN>s*6  5''     " cC`st|dst|}n|dkrMtjdddf|j}n`tj||j}tjg|j}x(|D] }tjddd||>> A = np.arange(8).reshape((2,2,2)) >>> A array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> flip(A, 0) array([[[4, 5], [6, 7]], [[0, 1], [2, 3]]]) >>> flip(A, 1) array([[[2, 3], [0, 1]], [[6, 7], [4, 5]]]) >>> np.flip(A) array([[[7, 6], [5, 4]], [[3, 2], [1, 0]]]) >>> np.flip(A, (0, 2)) array([[[5, 4], [7, 6]], [[1, 0], [3, 2]]]) >>> A = np.random.randn(3,4,5) >>> np.all(flip(A,2) == A[:,:,::-1,...]) True RjNi( thasattrR tNonetnpts_Rjt_nxtnormalize_axis_tupleRg(Rltaxistindexertax((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRMsP #  cC`s'yt|Wntk r"tSXtS(sw Check whether or not an object can be iterated over. Parameters ---------- y : object Input object. Returns ------- b : bool Return ``True`` if the object has an iterator method or is a sequence and ``False`` otherwise. Examples -------- >>> np.iterable([1, 2, 3]) True >>> np.iterable(2) False (titert TypeErrortFalsetTrue(ty((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyREs  cC`stj|}|d krI|j|}|jj|j|j}nttj|}t|jjtjtj frtj |j|jd}ntj |j|j}|j |j kr\|d krt dn|j dkrt dn|j d|j |kr#tdntj||j dd |j }|jd|}n|jd|d |}tj|d krtd ntj||d |j||}|r|j |j krtj||j j}n||fS|Sd S(s Compute the weighted average along the specified axis. Parameters ---------- a : array_like Array containing data to be averaged. If `a` is not an array, a conversion is attempted. axis : None or int or tuple of ints, optional Axis or axes along which to average `a`. The default, axis=None, will average over all of the elements of the input array. If axis is negative it counts from the last to the first axis. .. versionadded:: 1.7.0 If axis is a tuple of ints, averaging is performed on all of the axes specified in the tuple instead of a single axis or all the axes as before. weights : array_like, optional An array of weights associated with the values in `a`. Each value in `a` contributes to the average according to its associated weight. The weights array can either be 1-D (in which case its length must be the size of `a` along the given axis) or of the same shape as `a`. If `weights=None`, then all data in `a` are assumed to have a weight equal to one. returned : bool, optional Default is `False`. If `True`, the tuple (`average`, `sum_of_weights`) is returned, otherwise only the average is returned. If `weights=None`, `sum_of_weights` is equivalent to the number of elements over which the average is taken. Returns ------- average, [sum_of_weights] : array_type or double Return the average along the specified axis. When returned is `True`, return a tuple with the average as the first element and the sum of the weights as the second element. The return type is `Float` if `a` is of integer type, otherwise it is of the same type as `a`. `sum_of_weights` is of the same type as `average`. Raises ------ ZeroDivisionError When all weights along axis are zero. See `numpy.ma.average` for a version robust to this type of error. TypeError When the length of 1D `weights` is not the same as the shape of `a` along axis. See Also -------- mean ma.average : average for masked arrays -- useful if your data contains "missing" values Examples -------- >>> data = range(1,5) >>> data [1, 2, 3, 4] >>> np.average(data) 2.5 >>> np.average(range(1,11), weights=range(10,0,-1)) 4.0 >>> data = np.arange(6).reshape((3,2)) >>> data array([[0, 1], [2, 3], [4, 5]]) >>> np.average(data, axis=1, weights=[1./4, 3./4]) array([ 0.75, 2.75, 4.75]) >>> np.average(data, weights=[1./4, 3./4]) Traceback (most recent call last): ... TypeError: Axis must be specified when shapes of a and weights differ. tf8s;Axis must be specified when shapes of a and weights differ.is81D weights expected when shapes of a and weights differ.is5Length of weights not compatible with specified axis.iRvtdtypegs(Weights sum to zero, can't be normalizedN(i(RrR RqR.Rttypetsizet issubclassRtbool_t result_typetshapeRzRjRit broadcast_totswapaxesR0R/tZeroDivisionErrorRRD(taRvtweightstreturnedtavgtscltwgtt result_dtype((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRSs<Q !    $ % cC`sWt|d|d|}|jjtdkrStj|j rStdn|S(sTConvert the input to an array, checking for NaNs or Infs. Parameters ---------- a : array_like Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Success requires no NaNs or Infs. dtype : data-type, optional By default, the data-type is inferred from the input data. order : {'C', 'F'}, optional Whether to use row-major (C-style) or column-major (Fortran-style) memory representation. Defaults to 'C'. Returns ------- out : ndarray Array interpretation of `a`. No copy is performed if the input is already an ndarray. If `a` is a subclass of ndarray, a base class ndarray is returned. Raises ------ ValueError Raises ValueError if `a` contains NaN (Not a Number) or Inf (Infinity). See Also -------- asarray : Create and array. asanyarray : Similar function which passes through subclasses. ascontiguousarray : Convert input to a contiguous array. asfarray : Convert input to a floating point ndarray. asfortranarray : Convert input to an ndarray with column-major memory order. fromiter : Create an array from an iterator. fromfunction : Construct an array by executing a function on grid positions. Examples -------- Convert a list into an array. If all elements are finite ``asarray_chkfinite`` is identical to ``asarray``. >>> a = [1, 2] >>> np.asarray_chkfinite(a, dtype=float) array([1., 2.]) Raises ValueError if array_like contains Nans or Infs. >>> a = [1, 2, np.inf] >>> try: ... np.asarray_chkfinite(a) ... except ValueError: ... print('ValueError') ... ValueError RtordertAllFloats#array must not contain infs or NaNs(R RtcharR1RrtisfinitetallRi(RRR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRRs <, c O`st|}t|}t|sMt|dttf rY|jdkrY|g}nt|dt}t|}||dkrt j |dddt }t j ||gdd}|d7}n.||krt dj|||dnt|j|j}x{t|D]m} || } t| tjsN| ||| = 0``. >>> x = np.linspace(-2.5, 2.5, 6) >>> np.piecewise(x, [x < 0, x >= 0], [-1, 1]) array([-1., -1., -1., 1., 1., 1.]) Define the absolute value, which is ``-x`` for ``x <0`` and ``x`` for ``x >= 0``. >>> np.piecewise(x, [x < 0, x >= 0], [lambda x: -x, lambda x: x]) array([ 2.5, 1.5, 0.5, 0.5, 1.5, 2.5]) Apply the same function to a scalar value. >>> y = -2 >>> np.piecewise(y, [y < 0, y >= 0], [lambda x: -x, lambda x: x]) array(2) iRiRvtkeepdimss<with {} condition(s), either {} or {} functions are expected(R RhRt isinstancetlistRRjR tboolRrR/R|R RiRkRRRtrangetcollections_abctCallableR( txtcondlisttfunclisttargstkwtn2tntcondelseR}Rmtitemtvals((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRBs0W   )     !c C`s9t|t|kr'tdnt|dkr`tjdtddtj|d Sg|D]}tj|^qg}|jtj|tj|}tj |}tj |}t }xt t|D]u}||}|j j tjk rtj|j tjr;||jt||>> x = np.arange(10) >>> condlist = [x<3, x>5] >>> choicelist = [x, x**2] >>> np.select(condlist, choicelist) array([ 0, 1, 2, 0, 0, 0, 36, 49, 64, 81]) s7list of cases must be same length as list of conditionsisIselect with an empty condition list is not possibleand will be deprecatedt stacklevelis7invalid entry {} in condlist: should be boolean ndarraysselect condlists containing integer ndarrays is deprecated and will be removed in the future. Use `.astype(bool)` to convert to bools.iiNR((RhRitwarningstwarntDeprecationWarningRrR RdRtbroadcast_arraysR{RRRRt issubdtypeRtastypeRR|RkRjRtfulltziptcopyto( Rt choicelisttdefaulttchoiceRtdeprecated_intstitcondtmsgt result_shapetresult((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRAJsB&   "  !tKcC`st|d|dtS(s Return an array copy of the given object. Parameters ---------- a : array_like Input data. order : {'C', 'F', 'A', 'K'}, optional Controls the memory layout of the copy. 'C' means C-order, 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous, 'C' otherwise. 'K' means match the layout of `a` as closely as possible. (Note that this function and :meth:`ndarray.copy` are very similar, but have different default values for their order= arguments.) Returns ------- arr : ndarray Array interpretation of `a`. Notes ----- This is equivalent to: >>> np.array(a, copy=True) #doctest: +SKIP Examples -------- Create an array x, with a reference y and a copy z: >>> x = np.array([1, 2, 3]) >>> y = x >>> z = np.copy(x) Note that, when we modify x, y changes, but not z: >>> x[0] = 10 >>> x[0] == y[0] True >>> x[0] == z[0] False RRD(R R|(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRDs,cO`stj|}|j}|jdd}|dkrKtt|}ntj||}t |}t |}|dkrdg|}n|dkrtj|ddkr||}n||krt |}xt |D]\}} tj| dkrqn$tj| dkr3t dnt | |j ||kr_t dntj| } | | dkjr| d} n| ||>> f = np.array([1, 2, 4, 7, 11, 16], dtype=float) >>> np.gradient(f) array([ 1. , 1.5, 2.5, 3.5, 4.5, 5. ]) >>> np.gradient(f, 2) array([ 0.5 , 0.75, 1.25, 1.75, 2.25, 2.5 ]) Spacing can be also specified with an array that represents the coordinates of the values F along the dimensions. For instance a uniform spacing: >>> x = np.arange(f.size) >>> np.gradient(f, x) array([ 1. , 1.5, 2.5, 3.5, 4.5, 5. ]) Or a non uniform one: >>> x = np.array([0., 1., 1.5, 3.5, 4., 6.], dtype=float) >>> np.gradient(f, x) array([ 1. , 3. , 3.5, 6.7, 6.9, 2.5]) For two dimensional arrays, the return will be two arrays ordered by axis. In this example the first array stands for the gradient in rows and the second one in columns direction: >>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=float)) [array([[ 2., 2., -1.], [ 2., 2., -1.]]), array([[ 1. , 2.5, 4. ], [ 1. , 1. , 1. ]])] In this example the spacing is also specified: uniform for axis=0 and non uniform for axis=1 >>> dx = 2. >>> y = [1., 1.5, 3.5] >>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=float), dx, y) [array([[ 1. , 1. , -0.5], [ 1. , 1. , -0.5]]), array([[ 2. , 2. , 2. ], [ 2. , 1.7, 0.5]])] It is possible to specify how boundaries are treated using `edge_order` >>> x = np.array([0, 1, 2, 3, 4]) >>> f = x**2 >>> np.gradient(f, edge_order=1) array([ 1., 2., 4., 6., 7.]) >>> np.gradient(f, edge_order=2) array([-0., 2., 4., 6., 8.]) The `axis` keyword can be used to specify a subset of axes of which the gradient is calculated >>> np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=float), axis=0) array([[ 2., 2., -1.], [ 2., 2., -1.]]) Notes ----- Assuming that :math:`f\in C^{3}` (i.e., :math:`f` has at least 3 continuous derivatives) and let :math:`h_{*}` be a non-homogeneous stepsize, we minimize the "consistency error" :math:`\eta_{i}` between the true gradient and its estimate from a linear combination of the neighboring grid-points: .. math:: \eta_{i} = f_{i}^{\left(1\right)} - \left[ \alpha f\left(x_{i}\right) + \beta f\left(x_{i} + h_{d}\right) + \gamma f\left(x_{i}-h_{s}\right) \right] By substituting :math:`f(x_{i} + h_{d})` and :math:`f(x_{i} - h_{s})` with their Taylor series expansion, this translates into solving the following the linear system: .. math:: \left\{ \begin{array}{r} \alpha+\beta+\gamma=0 \\ \beta h_{d}-\gamma h_{s}=1 \\ \beta h_{d}^{2}+\gamma h_{s}^{2}=0 \end{array} \right. The resulting approximation of :math:`f_{i}^{(1)}` is the following: .. math:: \hat f_{i}^{(1)} = \frac{ h_{s}^{2}f\left(x_{i} + h_{d}\right) + \left(h_{d}^{2} - h_{s}^{2}\right)f\left(x_{i}\right) - h_{d}^{2}f\left(x_{i}-h_{s}\right)} { h_{s}h_{d}\left(h_{d} + h_{s}\right)} + \mathcal{O}\left(\frac{h_{d}h_{s}^{2} + h_{s}h_{d}^{2}}{h_{d} + h_{s}}\right) It is worth noting that if :math:`h_{s}=h_{d}` (i.e., data are evenly spaced) we find the standard second order approximation: .. math:: \hat f_{i}^{(1)}= \frac{f\left(x_{i+1}\right) - f\left(x_{i-1}\right)}{2h} + \mathcal{O}\left(h^{2}\right) With a similar procedure the forward/backward approximations used for boundaries can be derived. References ---------- .. [1] Quarteroni A., Sacco R., Saleri F. (2007) Numerical Mathematics (Texts in Applied Mathematics). New York: Springer. .. [2] Durran D. R. (1999) Numerical Methods for Wave Equations in Geophysical Fluid Dynamics. New York: Springer. .. [3] Fornberg B. (1988) Generation of Finite Difference Formulas on Arbitrarily Spaced Grids, Mathematics of Computation 51, no. 184 : 699-706. `PDF `_. Rvig?is&distances must be either scalars or 1dsGwhen 1d, distances must match the length of the corresponding dimensionsinvalid number of argumentst edge_orders%"{}" are not valid keyword arguments.s", "is)'edge_order' greater than 2 not supportedtdatetimet timedeltaslShape of array too small to calculate a numerical gradient, at least (edge_order + 1) elements are required.Riig@ggig?gg?N($RrR RjtpopRqRgRRtRuRhRt enumerateRiRRGRRzRktjointkeystsliceRRt datetime64tnametreplacetviewt timedelta64RtinexacttdoubleRRRtintRd(tftvarargstkwargstNRntlen_axesRtdxRt distancestdiffxRtoutvalstslice1tslice2tslice3tslice4totypeRvtax_dxtouttuniform_spacingtdx1tdx2RtbtcRtdx_0tdx_n((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRHs     %          3   B    ,   /         B         B  icC`s |dkr|S|dkr5tdt|nt|}|j}t||}tdg|}tdg|}tdd||>> u8_arr = np.array([1, 0], dtype=np.uint8) >>> np.diff(u8_arr) array([255], dtype=uint8) >>> u8_arr[1,...] - u8_arr[0,...] array(255, np.uint8) If this is not desirable, then the array should be cast to a larger integer type first: >>> i16_arr = u8_arr.astype(np.int16) >>> np.diff(i16_arr) array([-1], dtype=int16) Examples -------- >>> x = np.array([1, 2, 4, 7, 0]) >>> np.diff(x) array([ 1, 2, 3, -7]) >>> np.diff(x, n=2) array([ 1, 1, -10]) >>> x = np.array([[1, 3, 6, 10], [0, 5, 6, 8]]) >>> np.diff(x) array([[2, 3, 4], [5, 1, 2]]) >>> np.diff(x, axis=0) array([[-1, 2, 0, -2]]) >>> x = np.arange('1066-10-13', '1066-10-16', dtype=np.datetime64) >>> np.diff(x) array([1, 1], dtype='timedelta64[D]') is#order must be non-negative but got iiN(RitreprR RjR9RRqRgRRrRR(R)R(RRRvtndRRtopt_((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRG7s$L      c C`stj|}tj|r0t}tj}nt}tj}|dk r|dkrftdnt |}d}d}tj|dtj}tj|dtj}tj|d|}|j dks|j dkrtdn|j d|j dkrtdn||}||}tj |}||}||}tj |d|||dd!|f}tj |d||dd!f}n||||||S( s One-dimensional linear interpolation. Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (`xp`, `fp`), evaluated at `x`. Parameters ---------- x : array_like The x-coordinates at which to evaluate the interpolated values. xp : 1-D sequence of floats The x-coordinates of the data points, must be increasing if argument `period` is not specified. Otherwise, `xp` is internally sorted after normalizing the periodic boundaries with ``xp = xp % period``. fp : 1-D sequence of float or complex The y-coordinates of the data points, same length as `xp`. left : optional float or complex corresponding to fp Value to return for `x < xp[0]`, default is `fp[0]`. right : optional float or complex corresponding to fp Value to return for `x > xp[-1]`, default is `fp[-1]`. period : None or float, optional A period for the x-coordinates. This parameter allows the proper interpolation of angular x-coordinates. Parameters `left` and `right` are ignored if `period` is specified. .. versionadded:: 1.10.0 Returns ------- y : float or complex (corresponding to fp) or ndarray The interpolated values, same shape as `x`. Raises ------ ValueError If `xp` and `fp` have different length If `xp` or `fp` are not 1-D sequences If `period == 0` Notes ----- Does not check that the x-coordinate sequence `xp` is increasing. If `xp` is not increasing, the results are nonsense. A simple check for increasing is:: np.all(np.diff(xp) > 0) Examples -------- >>> xp = [1, 2, 3] >>> fp = [3, 2, 0] >>> np.interp(2.5, xp, fp) 1.0 >>> np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp) array([ 3. , 3. , 2.5 , 0.56, 0. ]) >>> UNDEF = -99.0 >>> np.interp(3.14, xp, fp, right=UNDEF) -99.0 Plot an interpolant to the sine function: >>> x = np.linspace(0, 2*np.pi, 10) >>> y = np.sin(x) >>> xvals = np.linspace(0, 2*np.pi, 50) >>> yinterp = np.interp(xvals, x, y) >>> import matplotlib.pyplot as plt >>> plt.plot(x, y, 'o') [] >>> plt.plot(xvals, yinterp, '-x') [] >>> plt.show() Interpolation with periodic x-coordinates: >>> x = [-180, -170, -185, 185, -10, -5, 0, 365] >>> xp = [190, -190, 350, -350] >>> fp = [5, 10, 3, 4] >>> np.interp(x, xp, fp, period=360) array([7.5, 5., 8.75, 6.25, 3., 3.25, 3.5, 3.75]) Complex interpolation: >>> x = [1.5, 4.0] >>> xp = [2,3,5] >>> fp = [1.0j, 0, 2+3j] >>> np.interp(x, xp, fp) array([ 0.+1.j , 1.+1.5j]) isperiod must be a non-zero valueRis!Data points must be 1-D sequencess$fp and xp are not of the same lengthiN(RrR t iscomplexobjtcompiled_interp_complext complex128tcompiled_interptfloat64RqRitabsRjRtargsortR ( Rtxptfptlefttrighttperiodt interp_funct input_dtypetasort_xp((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR:s6`         +&cC`so|rdt}nd}t|}t|jjtjrR|j}|j}n d}|}t |||S(s Return the angle of the complex argument. Parameters ---------- z : array_like A complex number or sequence of complex numbers. deg : bool, optional Return angle in degrees if True, radians if False (default). Returns ------- angle : ndarray or scalar The counterclockwise angle from the positive real axis on the complex plane, with dtype as numpy.float64. See Also -------- arctan2 absolute Examples -------- >>> np.angle([1.0, 1.0j, 1+1j]) # in radians array([ 0. , 1.57079633, 0.78539816]) >>> np.angle(1+1j, deg=True) # in degrees 45.0 ig?i( RR RRRRttcomplexfloatingtimagtrealR(tztdegtfacttzimagtzreal((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRIs    c C`st|}|j}t|d|}td d g|}tdd ||>> phase = np.linspace(0, np.pi, num=5) >>> phase[3:] += np.pi >>> phase array([ 0. , 0.78539816, 1.57079633, 5.49778714, 6.28318531]) >>> np.unwrap(phase) array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) RviiRiRDRtdN(R RjRGRRqRgR%RRtRRR R|tcumsum( tptdiscontRvRtddRtddmodt ph_correcttup((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRJKs)   ' "cC`st|dt}|jt|jjtjs|jjdkrS|j dS|jjdkrr|j dS|j dSn|SdS(s Sort a complex array using the real part first, then the imaginary part. Parameters ---------- a : array_like Input array Returns ------- out : complex ndarray Always returns a sorted complex array. Examples -------- >>> np.sort_complex([5, 3, 6, 2, 1]) array([ 1.+0.j, 2.+0.j, 3.+0.j, 5.+0.j, 6.+0.j]) >>> np.sort_complex([1 + 2j, 2 - 1j, 3 - 2j, 3 - 3j, 3 + 5j]) array([ 1.+2.j, 2.-1.j, 3.-3.j, 3.-2.j, 3.+5.j]) RDtbhBHtFtgtGtDN( R R|R,RRRRtRRR(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRKs   tfbcC`sd}|j}d|krLx+|D] }|dkr;Pq%|d}q%Wnt|}d|krx8|dddD] }|dkrPqx|d}qxWn|||!S(s3 Trim the leading and/or trailing zeros from a 1-D array or sequence. Parameters ---------- filt : 1-D array or sequence Input array. trim : str, optional A string with 'f' representing trim from front and 'b' to trim from back. Default is 'fb', trim zeros from both front and back of the array. Returns ------- trimmed : 1-D array or sequence The result of trimming the input. The input data type is preserved. Examples -------- >>> a = np.array((0, 0, 0, 1, 2, 3, 0, 2, 1, 0)) >>> np.trim_zeros(a) array([1, 2, 3, 0, 2, 1]) >>> np.trim_zeros(a, 'b') array([0, 0, 0, 1, 2, 3, 0, 2, 1]) The input data type is preserved, list/tuple in means list/tuple out. >>> np.trim_zeros([0, 1, 2, 0]) [1, 2] iRgitBNi(tupperRh(tfiltttrimtfirstRtlast((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRCs!       cC`syX|j}|jdkr"|S|jttg|d|d kf}||SWn*tk rtt|}t|SXdS(sW This function is deprecated. Use numpy.lib.arraysetops.unique() instead. iiiN( tflattenRR,R R|tAttributeErrortsortedtsetR (Rttmptidxtitems((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pytuniques  #  cC`s&tjt|tt|dS(s Return the elements of an array that satisfy some condition. This is equivalent to ``np.compress(ravel(condition), ravel(arr))``. If `condition` is boolean ``np.extract`` is equivalent to ``arr[condition]``. Note that `place` does the exact opposite of `extract`. Parameters ---------- condition : array_like An array whose nonzero or True entries indicate the elements of `arr` to extract. arr : array_like Input array of the same size as `condition`. Returns ------- extract : ndarray Rank 1 array of values from `arr` where `condition` is True. See Also -------- take, put, copyto, compress, place Examples -------- >>> arr = np.arange(12).reshape((3, 4)) >>> arr array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> condition = np.mod(arr, 3)==0 >>> condition array([[ True, False, False, True], [False, False, True, False], [False, True, False, False]]) >>> np.extract(condition, arr) array([0, 3, 6, 9]) If `condition` is boolean: >>> arr[condition] array([0, 3, 6, 9]) i(RtRR*R+(t conditiontarr((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyROs0cC`sFt|tjs6tdjdt|jnt|||S(s Change elements of an array based on conditional and input values. Similar to ``np.copyto(arr, vals, where=mask)``, the difference is that `place` uses the first N elements of `vals`, where N is the number of True values in `mask`, while `copyto` uses the elements where `mask` is True. Note that `extract` does the exact opposite of `place`. Parameters ---------- arr : ndarray Array to put data into. mask : array_like Boolean mask array. Must have the same size as `a`. vals : 1-D sequence Values to put into `a`. Only the first N elements are used, where N is the number of True values in `mask`. If `vals` is smaller than N, it will be repeated, and if elements of `a` are to be masked, this sequence must be non-empty. See Also -------- copyto, put, take, extract Examples -------- >>> arr = np.arange(6).reshape(2, 3) >>> np.place(arr, arr>2, [44, 55]) >>> arr array([[ 0, 1, 2], [44, 55, 44]]) s,argument 1 must be numpy.ndarray, not {name}R(RRrRRzRkRt__name__R5(RtmaskR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRPs$ cC`sQ|dkrtj}n|r2|jd|n|jd||jdS(s2 Display a message on a device. Parameters ---------- mesg : str Message to display. device : object Device to write message. If None, defaults to ``sys.stdout`` which is very similar to ``print``. `device` needs to have ``write()`` and ``flush()`` methods. linefeed : bool, optional Option whether to print a line feed or not. Defaults to True. Raises ------ AttributeError If `device` does not have a ``write()`` or ``flush()`` method. Examples -------- Besides ``sys.stdout``, a file-like object can also be used as it has both required methods: >>> from io import StringIO >>> buf = StringIO() >>> np.disp(u'"Display" in a file', device=buf) >>> buf.getvalue() '"Display" in a file\n' s%s s%sN(Rqtsyststdouttwritetflush(tmesgtdevicetlinefeed((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRLJs   s\w+s(?:{0:}(?:,{0:})*)?s\({}\)s{0:}(?:,{0:})*s ^{0:}->{0:}$cC`sGtjt|s*tdj|ntd|jdDS(ss Parse string signatures for a generalized universal function. Arguments --------- signature : string Generalized universal function signature, e.g., ``(m,n),(n,p)->(m,p)`` for ``np.matmul``. Returns ------- Tuple of input and output core dimensions parsed from the signature, each of the form List[Tuple[str, ...]]. s not a valid gufunc signature: {}cs`sF|]<}gtjt|D]}ttjt|^qVqdS(N(tretfindallt _ARGUMENTRgt_DIMENSION_NAME(t.0targ_listtarg((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pys ss->(R#tmatcht _SIGNATURERiRkRgtsplit(t signature((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_parse_gufunc_signature|s  cC`s|s dSt|}|j|krAtd|j|fn|j| }xft||D]U\}}||kr|||krtd||||fqq_|||s(Rg(R<R/tlist_of_core_dimsR0((R/s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_calculate_shapesscC`s5t|||}tdt||D}|S(s/Helper for creating output arrays in vectorize.cs`s*|] \}}tj|d|VqdS(RN(RrR(R'RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pys s(R?RgR(R<R/R>tdtypestshapestarrays((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_create_arrayss cB`sJeZdZdddeddZdZdZdZdZ RS(s@ vectorize(pyfunc, otypes=None, doc=None, excluded=None, cache=False, signature=None) Generalized function class. Define a vectorized function which takes a nested sequence of objects or numpy arrays as inputs and returns an single or tuple of numpy array as output. The vectorized function evaluates `pyfunc` over successive tuples of the input arrays like the python map function, except it uses the broadcasting rules of numpy. The data type of the output of `vectorized` is determined by calling the function with the first element of the input. This can be avoided by specifying the `otypes` argument. Parameters ---------- pyfunc : callable A python function or method. otypes : str or list of dtypes, optional The output data type. It must be specified as either a string of typecode characters or a list of data type specifiers. There should be one data type specifier for each output. doc : str, optional The docstring for the function. If `None`, the docstring will be the ``pyfunc.__doc__``. excluded : set, optional Set of strings or integers representing the positional or keyword arguments for which the function will not be vectorized. These will be passed directly to `pyfunc` unmodified. .. versionadded:: 1.7.0 cache : bool, optional If `True`, then cache the first function call that determines the number of outputs if `otypes` is not provided. .. versionadded:: 1.7.0 signature : string, optional Generalized universal function signature, e.g., ``(m,n),(n)->(m)`` for vectorized matrix-vector multiplication. If provided, ``pyfunc`` will be called with (and expected to return) arrays with shapes given by the size of corresponding core dimensions. By default, ``pyfunc`` is assumed to take scalars as input and output. .. versionadded:: 1.12.0 Returns ------- vectorized : callable Vectorized function. Examples -------- >>> def myfunc(a, b): ... "Return a-b if a>b, otherwise return a+b" ... if a > b: ... return a - b ... else: ... return a + b >>> vfunc = np.vectorize(myfunc) >>> vfunc([1, 2, 3, 4], 2) array([3, 4, 1, 2]) The docstring is taken from the input function to `vectorize` unless it is specified: >>> vfunc.__doc__ 'Return a-b if a>b, otherwise return a+b' >>> vfunc = np.vectorize(myfunc, doc='Vectorized `myfunc`') >>> vfunc.__doc__ 'Vectorized `myfunc`' The output type is determined by evaluating the first element of the input, unless it is specified: >>> out = vfunc([1, 2, 3, 4], 2) >>> type(out[0]) >>> vfunc = np.vectorize(myfunc, otypes=[float]) >>> out = vfunc([1, 2, 3, 4], 2) >>> type(out[0]) The `excluded` argument can be used to prevent vectorizing over certain arguments. This can be useful for array-like arguments of a fixed length such as the coefficients for a polynomial as in `polyval`: >>> def mypolyval(p, x): ... _p = list(p) ... res = _p.pop(0) ... while _p: ... res = res*x + _p.pop(0) ... return res >>> vpolyval = np.vectorize(mypolyval, excluded=['p']) >>> vpolyval(p=[1, 2, 3], x=[0, 1]) array([3, 6]) Positional arguments may also be excluded by specifying their position: >>> vpolyval.excluded.add(0) >>> vpolyval([1, 2, 3], x=[0, 1]) array([3, 6]) The `signature` argument allows for vectorizing functions that act on non-scalar arrays of fixed length. For example, you can use it for a vectorized calculation of Pearson correlation coefficient and its p-value: >>> import scipy.stats >>> pearsonr = np.vectorize(scipy.stats.pearsonr, ... signature='(n),(n)->(),()') >>> pearsonr([[0, 1, 2, 3]], [[1, 2, 3, 4], [4, 3, 2, 1]]) (array([ 1., -1.]), array([ 0., 0.])) Or for a vectorized convolution: >>> convolve = np.vectorize(np.convolve, signature='(n),(m)->(k)') >>> convolve(np.eye(4), [1, 2, 1]) array([[ 1., 2., 1., 0., 0., 0.], [ 0., 1., 2., 1., 0., 0.], [ 0., 0., 1., 2., 1., 0.], [ 0., 0., 0., 1., 2., 1.]]) See Also -------- frompyfunc : Takes an arbitrary Python function and returns a ufunc Notes ----- The `vectorize` function is provided primarily for convenience, not for performance. The implementation is essentially a for loop. If `otypes` is not specified, then a call to the function with the first argument will be used to determine the number of outputs. The results of this call will be cached if `cache` is `True` to prevent calling the function twice. However, to implement the cache, the original function must be wrapped which will slow down subsequent calls, so only do this if your function is expensive. The new keyword argument interface and `excluded` argument support further degrades performance. References ---------- .. [1] NumPy Reference, section `Generalized Universal Function API `_. c C`sD||_||_||_d|_|dkr?|j|_n ||_t|trx|D],}|tdkr^t d|fq^q^WnXt |rdj g|D]}t j |j^q}n|dk rt dn||_|dkr t}nt||_|dk r7t||_n d|_dS(NtAllsInvalid otype specified: %stsInvalid otype specification(tpyfunctcacheR-Rqt_ufunct__doc__RtstrR1RiRERRtRRtotypesRtexcludedR.t_in_and_out_core_dims( tselfRFRKtdocRLRGR-RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt__init__xs,        1     c `sj} r)| r)j}|}nt|}gD]}||kr<|^q<gt|D]}||krg|^qgt|fd}gD]}||^q}|jgD]}|^qjd|d|S(s Return arrays with the results of `pyfunc` broadcast (vectorized) over `args` and `kwargs` not in `excluded`. c`s[x(tD]\}}|||ss?cannot call `vectorize` on size 0 inputs unless `otypes` is setic`srjS|SdS(N(R(RR(t_cacheRX(s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_funcs iREN(RiRKRqRhRFRHR R tbuiltinsR/tflatRGRRgRRRR( RNRXRRKtnouttufuncR)tinputstoutputsR^t_k((R]RXs6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_get_ufunc_and_otypess2   "      /c C`s|jdk r$|j||}n|s6|}n|jd|d|\}}g|D]$}t|dtdtdt^q[}||}|jdkrt|dtdtd|d}nFt gt ||D]*\} } t| dtdtd| ^q}|S( s1Vectorized call to `func` over positional `args`.RXRRDtsubokRiiN( R-Rqt_vectorize_call_with_signatureRfR R{R|tobjectRaRgR( RNRXRtresRbRKRRcRdRtt((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRZs . %@c`s|j\}}t|t|krLtdt|t|fntd|D}t||\}t||}gt||D]$\}}tj||dt ^q}d } |j } t|} x@tj |D]/|fd|D} t | tr+t| nd} | | krVtd| | fn| dkrn| f} n| d krx-t| |D]\}}t||qW| d krg| D]}t|j^q} nt||| } nx't| | D]\}}||sRgc3`s|]}|VqdS(N((R'R)(tindex(s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pys sis8wrong number of outputs from pyfunc: expected %r, got %rs?cannot call `vectorize` on size 0 inputs unless `otypes` is setc3`s(|]}|D]}|kVq qdS(N((R'tdimsR3(R/(s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pys =ssYcannot call `vectorize` with a signature including new output dimensions on size 0 inputsiN(RMRhRzRgR=R?RRrRR|RqRKtndindexRRiR4R RRCR_R/(RNRXRR9toutput_core_dimsR<t input_shapesR)RRdRKRatresultst n_resultsRR0toutput((R/Rls6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRh sR  7  !     %     N( Rt __module__RIRqR{RPR\RfRZRh(((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRQs   = cC`sl|dk r-|t|kr-tdntj|}|jdkrZtdn|dkr~tj|tj}nEtj|}|jdkrtdntj||tj}t|ddd|}| r|j ddkr|j }n|j ddkr-tjgj ddS|dk rt|d t ddd|}| r}|j ddkr}|j }ntj ||fd d}n|dkr|dkrd}qd}nd} |dk rtj|dt}tj|tj|kstd n|jdkr7td n|j d|j dkr`td nt|dkrtdn|} n|dk r5tj|dt}|jdkrtdn|j d|j dkrtdnt|dkrtdn| dkr(|} q5| |9} nt|d dd| dt\} } | d} | dkr|j d|} nJ|dkr| } n5|dkr| |} n| |t| || } | dkrtjdtddd} n|| dddf8}| dkr*|j } n || j } t|| j}|tjd| 9}|jS(s Estimate a covariance matrix, given data and weights. Covariance indicates the level to which two variables vary together. If we examine N-dimensional samples, :math:`X = [x_1, x_2, ... x_N]^T`, then the covariance matrix element :math:`C_{ij}` is the covariance of :math:`x_i` and :math:`x_j`. The element :math:`C_{ii}` is the variance of :math:`x_i`. See the notes for an outline of the algorithm. Parameters ---------- m : array_like A 1-D or 2-D array containing multiple variables and observations. Each row of `m` represents a variable, and each column a single observation of all those variables. Also see `rowvar` below. y : array_like, optional An additional set of variables and observations. `y` has the same form as that of `m`. rowvar : bool, optional If `rowvar` is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. bias : bool, optional Default normalization (False) is by ``(N - 1)``, where ``N`` is the number of observations given (unbiased estimate). If `bias` is True, then normalization is by ``N``. These values can be overridden by using the keyword ``ddof`` in numpy versions >= 1.5. ddof : int, optional If not ``None`` the default value implied by `bias` is overridden. Note that ``ddof=1`` will return the unbiased estimate, even if both `fweights` and `aweights` are specified, and ``ddof=0`` will return the simple average. See the notes for the details. The default value is ``None``. .. versionadded:: 1.5 fweights : array_like, int, optional 1-D array of integer frequency weights; the number of times each observation vector should be repeated. .. versionadded:: 1.10 aweights : array_like, optional 1-D array of observation vector weights. These relative weights are typically large for observations considered "important" and smaller for observations considered less "important". If ``ddof=0`` the array of weights can be used to assign probabilities to observation vectors. .. versionadded:: 1.10 Returns ------- out : ndarray The covariance matrix of the variables. See Also -------- corrcoef : Normalized covariance matrix Notes ----- Assume that the observations are in the columns of the observation array `m` and let ``f = fweights`` and ``a = aweights`` for brevity. The steps to compute the weighted covariance are as follows:: >>> w = f * a >>> v1 = np.sum(w) >>> v2 = np.sum(w * a) >>> m -= np.sum(m * w, axis=1, keepdims=True) / v1 >>> cov = np.dot(m * w, m.T) * v1 / (v1**2 - ddof * v2) Note that when ``a == 1``, the normalization factor ``v1 / (v1**2 - ddof * v2)`` goes over to ``1 / (np.sum(f) - ddof)`` as it should. Examples -------- Consider two variables, :math:`x_0` and :math:`x_1`, which correlate perfectly, but in opposite directions: >>> x = np.array([[0, 2], [1, 1], [2, 0]]).T >>> x array([[0, 1, 2], [2, 1, 0]]) Note how :math:`x_0` increases while :math:`x_1` decreases. The covariance matrix shows this clearly: >>> np.cov(x) array([[ 1., -1.], [-1., 1.]]) Note that element :math:`C_{0,1}`, which shows the correlation between :math:`x_0` and :math:`x_1`, is negative. Further, note how `x` and `y` are combined: >>> x = [-2.1, -1, 4.3] >>> y = [3, 1.1, 0.12] >>> X = np.stack((x, y), axis=0) >>> print(np.cov(X)) [[ 11.71 -4.286 ] [ -4.286 2.14413333]] >>> print(np.cov(x, y)) [[ 11.71 -4.286 ] [ -4.286 2.14413333]] >>> print(np.cov(x)) 11.71 sddof must be integerism has more than 2 dimensionssy has more than 2 dimensionstndminRiiRDRvsfweights must be integers'cannot handle multidimensional fweightss,incompatible numbers of samples and fweightssfweights cannot be negatives'cannot handle multidimensional aweightss,incompatible numbers of samples and aweightssaweights cannot be negativeRRs!Degrees of freedom <= 0 for sliceRgN(RqRRiRrR RjRRR RtTtreshapeR{R tfloatRRRzt RuntimeErrorR/RSR|R0RRtRuntimeWarningRtconjt true_dividetsqueeze(RlR}trowvartbiastddoftfweightstaweightsRtXtwRtw_sumRtX_TR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRTIsr                      $             cC`s |tjk s|tjk r7tjdtddnt|||}yt|}Wntk rq||SXt|j }||dddf}||dddf}tj |j ddd|j tj |rtj |j ddd|j n|S(s Return Pearson product-moment correlation coefficients. Please refer to the documentation for `cov` for more detail. The relationship between the correlation coefficient matrix, `R`, and the covariance matrix, `C`, is .. math:: R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } } The values of `R` are between -1 and 1, inclusive. Parameters ---------- x : array_like A 1-D or 2-D array containing multiple variables and observations. Each row of `x` represents a variable, and each column a single observation of all those variables. Also see `rowvar` below. y : array_like, optional An additional set of variables and observations. `y` has the same shape as `x`. rowvar : bool, optional If `rowvar` is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. bias : _NoValue, optional Has no effect, do not use. .. deprecated:: 1.10.0 ddof : _NoValue, optional Has no effect, do not use. .. deprecated:: 1.10.0 Returns ------- R : ndarray The correlation coefficient matrix of the variables. See Also -------- cov : Covariance matrix Notes ----- Due to floating point rounding the resulting array may not be Hermitian, the diagonal elements may not be 1, and the elements may not satisfy the inequality abs(a) <= 1. The real and imaginary parts are clipped to the interval [-1, 1] in an attempt to improve on that situation but is not much help in the complex case. This function accepts but discards arguments `bias` and `ddof`. This is for backwards compatibility with previous versions of this function. These arguments had no effect on the return values of the function and can be safely ignored in this and previous versions of numpy. s/bias and ddof have no effect and are deprecatedRiNiiR(Rrt_NoValueRRRRTR3RiR#RRqtclipRR(RR}R~RRRRtstddev((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRU s:   "cC`s~|dkrtgS|dkr/tdtStd|}ddtdt||ddtdt||dS(s Return the Blackman window. The Blackman window is a taper formed by using the first three terms of a summation of cosines. It was designed to have close to the minimal leakage possible. It is close to optimal, only slightly worse than a Kaiser window. Parameters ---------- M : int Number of points in the output window. If zero or less, an empty array is returned. Returns ------- out : ndarray The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). See Also -------- bartlett, hamming, hanning, kaiser Notes ----- The Blackman window is defined as .. math:: w(n) = 0.42 - 0.5 \cos(2\pi n/M) + 0.08 \cos(4\pi n/M) Most references to the Blackman window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. It is also known as an apodization (which means "removing the foot", i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function. It is known as a "near optimal" tapering function, almost as good (by some measures) as the kaiser window. References ---------- Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, Dover Publications, New York. Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471. Examples -------- >>> np.blackman(12) array([ -1.38777878e-17, 3.26064346e-02, 1.59903635e-01, 4.14397981e-01, 7.36045180e-01, 9.67046769e-01, 9.67046769e-01, 7.36045180e-01, 4.14397981e-01, 1.59903635e-01, 3.26064346e-02, -1.38777878e-17]) Plot the window and the frequency response: >>> from numpy.fft import fft, fftshift >>> window = np.blackman(51) >>> plt.plot(window) [] >>> plt.title("Blackman window") >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = np.abs(fftshift(A)) >>> freq = np.linspace(-0.5, 0.5, len(A)) >>> response = 20 * np.log10(mag) >>> response = np.clip(response, -100, 100) >>> plt.plot(freq, response) [] >>> plt.title("Frequency response of Blackman window") >>> plt.ylabel("Magnitude [dB]") >>> plt.xlabel("Normalized frequency [cycles per sample]") >>> plt.axis('tight') (-0.5, 0.5, -100.0, ...) >>> plt.show() iigzG?g?g@g{Gz?g@(R RRxR R!R(tMR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR\m s Z    cC`s{|dkrtgS|dkr/tdtStd|}tt||ddd||ddd||dS(s Return the Bartlett window. The Bartlett window is very similar to a triangular window, except that the end points are at zero. It is often used in signal processing for tapering a signal, without generating too much ripple in the frequency domain. Parameters ---------- M : int Number of points in the output window. If zero or less, an empty array is returned. Returns ------- out : array The triangular window, with the maximum value normalized to one (the value one appears only if the number of samples is odd), with the first and last samples equal to zero. See Also -------- blackman, hamming, hanning, kaiser Notes ----- The Bartlett window is defined as .. math:: w(n) = \frac{2}{M-1} \left( \frac{M-1}{2} - \left|n - \frac{M-1}{2}\right| \right) Most references to the Bartlett window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. Note that convolution with this window produces linear interpolation. It is also known as an apodization (which means"removing the foot", i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function. The fourier transform of the Bartlett is the product of two sinc functions. Note the excellent discussion in Kanasewich. References ---------- .. [1] M.S. Bartlett, "Periodogram Analysis and Continuous Spectra", Biometrika 37, 1-16, 1950. .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The University of Alberta Press, 1975, pp. 109-110. .. [3] A.V. Oppenheim and R.W. Schafer, "Discrete-Time Signal Processing", Prentice-Hall, 1999, pp. 468-471. .. [4] Wikipedia, "Window function", http://en.wikipedia.org/wiki/Window_function .. [5] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, "Numerical Recipes", Cambridge University Press, 1986, page 429. Examples -------- >>> np.bartlett(12) array([ 0. , 0.18181818, 0.36363636, 0.54545455, 0.72727273, 0.90909091, 0.90909091, 0.72727273, 0.54545455, 0.36363636, 0.18181818, 0. ]) Plot the window and its frequency response (requires SciPy and matplotlib): >>> from numpy.fft import fft, fftshift >>> window = np.bartlett(51) >>> plt.plot(window) [] >>> plt.title("Bartlett window") >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = np.abs(fftshift(A)) >>> freq = np.linspace(-0.5, 0.5, len(A)) >>> response = 20 * np.log10(mag) >>> response = np.clip(response, -100, 100) >>> plt.plot(freq, response) [] >>> plt.title("Frequency response of Bartlett window") >>> plt.ylabel("Magnitude [dB]") >>> plt.xlabel("Normalized frequency [cycles per sample]") >>> plt.axis('tight') (-0.5, 0.5, -100.0, ...) >>> plt.show() iig@(R RRxR RR"(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR[ s b    cC`s`|dkrtgS|dkr/tdtStd|}ddtdt||dS(sa Return the Hanning window. The Hanning window is a taper formed by using a weighted cosine. Parameters ---------- M : int Number of points in the output window. If zero or less, an empty array is returned. Returns ------- out : ndarray, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). See Also -------- bartlett, blackman, hamming, kaiser Notes ----- The Hanning window is defined as .. math:: w(n) = 0.5 - 0.5cos\left(\frac{2\pi{n}}{M-1}\right) \qquad 0 \leq n \leq M-1 The Hanning was named for Julius von Hann, an Austrian meteorologist. It is also known as the Cosine Bell. Some authors prefer that it be called a Hann window, to help avoid confusion with the very similar Hamming window. Most references to the Hanning window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. It is also known as an apodization (which means "removing the foot", i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function. References ---------- .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, Dover Publications, New York. .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The University of Alberta Press, 1975, pp. 106-108. .. [3] Wikipedia, "Window function", http://en.wikipedia.org/wiki/Window_function .. [4] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, "Numerical Recipes", Cambridge University Press, 1986, page 425. Examples -------- >>> np.hanning(12) array([ 0. , 0.07937323, 0.29229249, 0.57115742, 0.82743037, 0.97974649, 0.97974649, 0.82743037, 0.57115742, 0.29229249, 0.07937323, 0. ]) Plot the window and its frequency response: >>> from numpy.fft import fft, fftshift >>> window = np.hanning(51) >>> plt.plot(window) [] >>> plt.title("Hann window") >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = np.abs(fftshift(A)) >>> freq = np.linspace(-0.5, 0.5, len(A)) >>> response = 20 * np.log10(mag) >>> response = np.clip(response, -100, 100) >>> plt.plot(freq, response) [] >>> plt.title("Frequency response of the Hann window") >>> plt.ylabel("Magnitude [dB]") >>> plt.xlabel("Normalized frequency [cycles per sample]") >>> plt.axis('tight') (-0.5, 0.5, -100.0, ...) >>> plt.show() iig?g@(R RRxR R!R(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRZ9 s \    cC`s`|dkrtgS|dkr/tdtStd|}ddtdt||dS(sQ Return the Hamming window. The Hamming window is a taper formed by using a weighted cosine. Parameters ---------- M : int Number of points in the output window. If zero or less, an empty array is returned. Returns ------- out : ndarray The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). See Also -------- bartlett, blackman, hanning, kaiser Notes ----- The Hamming window is defined as .. math:: w(n) = 0.54 - 0.46cos\left(\frac{2\pi{n}}{M-1}\right) \qquad 0 \leq n \leq M-1 The Hamming was named for R. W. Hamming, an associate of J. W. Tukey and is described in Blackman and Tukey. It was recommended for smoothing the truncated autocovariance function in the time domain. Most references to the Hamming window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. It is also known as an apodization (which means "removing the foot", i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function. References ---------- .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, Dover Publications, New York. .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The University of Alberta Press, 1975, pp. 109-110. .. [3] Wikipedia, "Window function", http://en.wikipedia.org/wiki/Window_function .. [4] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, "Numerical Recipes", Cambridge University Press, 1986, page 425. Examples -------- >>> np.hamming(12) array([ 0.08 , 0.15302337, 0.34890909, 0.60546483, 0.84123594, 0.98136677, 0.98136677, 0.84123594, 0.60546483, 0.34890909, 0.15302337, 0.08 ]) Plot the window and the frequency response: >>> from numpy.fft import fft, fftshift >>> window = np.hamming(51) >>> plt.plot(window) [] >>> plt.title("Hamming window") >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = np.abs(fftshift(A)) >>> freq = np.linspace(-0.5, 0.5, len(A)) >>> response = 20 * np.log10(mag) >>> response = np.clip(response, -100, 100) >>> plt.plot(freq, response) [] >>> plt.title("Frequency response of Hamming window") >>> plt.ylabel("Magnitude [dB]") >>> plt.xlabel("Normalized frequency [cycles per sample]") >>> plt.axis('tight') (-0.5, 0.5, -100.0, ...) >>> plt.show() iigHzG?gq= ףp?g@(R RRxR R!R(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRY s Z    g4!\Tg}b3g0 Kg5dMv;p>g"c쑾g$>g'doҾgY(X?>gZY&+g|t(?gRBguZ?gI ^qga?g!Ng-Ί>?g-4pKgw?gWӿg*5N?gT`g0fFVg!g["d,->gmրVX>gna>g+A>gRx?gI墌k?g b?cC`s^|d}d}x?tdt|D](}|}|}|||||}q&Wd||S(Nigig?(RRh(RRtb0tb1Rtb2((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_chbevl> s cC`st|t|ddtS(Ng@i(R&Rt_i0A(R((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_i0_1J scC`s)t|td|dtt|S(Ng@@g@(R&Rt_i0BR#(R((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyt_i0_2N scC`s~t|j}t|}|dk}|| ||<|dk}t||||<|}t||||<|jS(s0 Modified Bessel function of the first kind, order 0. Usually denoted :math:`I_0`. This function does broadcast, but will *not* "up-cast" int dtype arguments unless accompanied by at least one float or complex dtype argument (see Raises below). Parameters ---------- x : array_like, dtype float or complex Argument of the Bessel function. Returns ------- out : ndarray, shape = x.shape, dtype = x.dtype The modified Bessel function evaluated at each of the elements of `x`. Raises ------ TypeError: array cannot be safely cast to required type If argument consists exclusively of int dtypes. See Also -------- scipy.special.iv, scipy.special.ive Notes ----- We use the algorithm published by Clenshaw [1]_ and referenced by Abramowitz and Stegun [2]_, for which the function domain is partitioned into the two intervals [0,8] and (8,inf), and Chebyshev polynomial expansions are employed in each interval. Relative error on the domain [0,30] using IEEE arithmetic is documented [3]_ as having a peak of 5.8e-16 with an rms of 1.4e-16 (n = 30000). References ---------- .. [1] C. W. Clenshaw, "Chebyshev series for mathematical functions", in *National Physical Laboratory Mathematical Tables*, vol. 5, London: Her Majesty's Stationery Office, 1962. .. [2] M. Abramowitz and I. A. Stegun, *Handbook of Mathematical Functions*, 10th printing, New York: Dover, 1964, pp. 379. http://www.math.sfu.ca/~cbm/aands/page_379.htm .. [3] http://kobesearch.cpan.org/htdocs/Math-Cephes/Math/Cephes.html Examples -------- >>> np.i0([0.]) array(1.0) >>> np.i0([0., 1. + 2j]) array([ 1.00000000+0.j , 0.18785373+0.64616944j]) ig @(RRDRRRR}(RR}tindtind2((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR_R s6   cC`s}ddlm}|dkr,tjdgStd|}|dd}||td|||d|t|S(s Return the Kaiser window. The Kaiser window is a taper formed by using a Bessel function. Parameters ---------- M : int Number of points in the output window. If zero or less, an empty array is returned. beta : float Shape parameter for window. Returns ------- out : array The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). See Also -------- bartlett, blackman, hamming, hanning Notes ----- The Kaiser window is defined as .. math:: w(n) = I_0\left( \beta \sqrt{1-\frac{4n^2}{(M-1)^2}} \right)/I_0(\beta) with .. math:: \quad -\frac{M-1}{2} \leq n \leq \frac{M-1}{2}, where :math:`I_0` is the modified zeroth-order Bessel function. The Kaiser was named for Jim Kaiser, who discovered a simple approximation to the DPSS window based on Bessel functions. The Kaiser window is a very good approximation to the Digital Prolate Spheroidal Sequence, or Slepian window, which is the transform which maximizes the energy in the main lobe of the window relative to total energy. The Kaiser can approximate many other windows by varying the beta parameter. ==== ======================= beta Window shape ==== ======================= 0 Rectangular 5 Similar to a Hamming 6 Similar to a Hanning 8.6 Similar to a Blackman ==== ======================= A beta value of 14 is probably a good starting point. Note that as beta gets large, the window narrows, and so the number of samples needs to be large enough to sample the increasingly narrow spike, otherwise NaNs will get returned. Most references to the Kaiser window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. It is also known as an apodization (which means "removing the foot", i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function. References ---------- .. [1] J. F. Kaiser, "Digital Filters" - Ch 7 in "Systems analysis by digital computer", Editors: F.F. Kuo and J.F. Kaiser, p 218-285. John Wiley and Sons, New York, (1966). .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The University of Alberta Press, 1975, pp. 177-178. .. [3] Wikipedia, "Window function", http://en.wikipedia.org/wiki/Window_function Examples -------- >>> np.kaiser(12, 14) array([ 7.72686684e-06, 3.46009194e-03, 4.65200189e-02, 2.29737120e-01, 5.99885316e-01, 9.45674898e-01, 9.45674898e-01, 5.99885316e-01, 2.29737120e-01, 4.65200189e-02, 3.46009194e-03, 7.72686684e-06]) Plot the window and the frequency response: >>> from numpy.fft import fft, fftshift >>> window = np.kaiser(51, 14) >>> plt.plot(window) [] >>> plt.title("Kaiser window") >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = np.abs(fftshift(A)) >>> freq = np.linspace(-0.5, 0.5, len(A)) >>> response = 20 * np.log10(mag) >>> response = np.clip(response, -100, 100) >>> plt.plot(freq, response) [] >>> plt.title("Frequency response of Kaiser window") >>> plt.ylabel("Magnitude [dB]") >>> plt.xlabel("Normalized frequency [cycles per sample]") >>> plt.axis('tight') (-0.5, 0.5, -100.0, ...) >>> plt.show() i(R_ig?g@(t numpy.dualR_RrR R R#Rx(RtbetaR_Rtalpha((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR] s w cC`s9tj|}tt|dkd|}t||S(s Return the sinc function. The sinc function is :math:`\sin(\pi x)/(\pi x)`. Parameters ---------- x : ndarray Array (possibly multi-dimensional) of values for which to to calculate ``sinc(x)``. Returns ------- out : ndarray ``sinc(x)``, which has the same shape as the input. Notes ----- ``sinc(0)`` is the limit value 1. The name sinc is short for "sine cardinal" or "sinus cardinalis". The sinc function is used in various signal processing applications, including in anti-aliasing, in the construction of a Lanczos resampling filter, and in interpolation. For bandlimited interpolation of discrete-time signals, the ideal interpolation kernel is proportional to the sinc function. References ---------- .. [1] Weisstein, Eric W. "Sinc Function." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/SincFunction.html .. [2] Wikipedia, "Sinc function", http://en.wikipedia.org/wiki/Sinc_function Examples -------- >>> x = np.linspace(-4, 4, 41) >>> np.sinc(x) array([ -3.89804309e-17, -4.92362781e-02, -8.40918587e-02, -8.90384387e-02, -5.84680802e-02, 3.89804309e-17, 6.68206631e-02, 1.16434881e-01, 1.26137788e-01, 8.50444803e-02, -3.89804309e-17, -1.03943254e-01, -1.89206682e-01, -2.16236208e-01, -1.55914881e-01, 3.89804309e-17, 2.33872321e-01, 5.04551152e-01, 7.56826729e-01, 9.35489284e-01, 1.00000000e+00, 9.35489284e-01, 7.56826729e-01, 5.04551152e-01, 2.33872321e-01, 3.89804309e-17, -1.55914881e-01, -2.16236208e-01, -1.89206682e-01, -1.03943254e-01, -3.89804309e-17, 8.50444803e-02, 1.26137788e-01, 1.16434881e-01, 6.68206631e-02, 3.89804309e-17, -5.84680802e-02, -8.90384387e-02, -8.40918587e-02, -4.92362781e-02, -3.89804309e-17]) >>> plt.plot(x, np.sinc(x)) [] >>> plt.title("Sinc Function") >>> plt.ylabel("Amplitude") >>> plt.xlabel("X") >>> plt.show() It works in 2-D as well: >>> x = np.linspace(-4, 4, 401) >>> xx = np.outer(x, x) >>> plt.imshow(np.sinc(xx)) ig#B ;(RrR RRR$(RR}((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRX sJcC`s)t|dtdt}|jd|S(sk Return a copy of an array sorted along the first axis. Parameters ---------- a : array_like Array to be sorted. Returns ------- sorted_array : ndarray Array of the same type and shape as `a`. See Also -------- sort Notes ----- ``np.msort(a)`` is equivalent to ``np.sort(a, axis=0)``. RgRDi(R R|R,(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRVc s c K`sKtj|}|jdd}|dk r%t|j}|j}tj||}x|D]}d||>> a = np.array([[10, 7, 4], [3, 2, 1]]) >>> a array([[10, 7, 4], [ 3, 2, 1]]) >>> np.median(a) 3.5 >>> np.median(a, axis=0) array([ 6.5, 4.5, 2.5]) >>> np.median(a, axis=1) array([ 7., 2.]) >>> m = np.median(a, axis=0) >>> out = np.zeros_like(m) >>> np.median(a, axis=0, out=m) array([ 6.5, 4.5, 2.5]) >>> m array([ 6.5, 4.5, 2.5]) >>> b = a.copy() >>> np.median(b, axis=1, overwrite_input=True) array([ 7., 2.]) >>> assert not np.all(a==b) >>> b = a.copy() >>> np.median(b, axis=None, overwrite_input=True) 3.5 >>> assert not np.all(a==b) RXRvRtoverwrite_inputN(Rt_medianRw(RRvRRRRRm((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRW s Q c C`s tj|}|dkr'|j}n |j|}|ddkra|d}|d|g}n|ddg}tj|jtjr|jdn|r|dkr|j }|j |q|j |d||}nt ||d|}|jdkr|j S|dkr'd}nt dg|j }|j|d} |j|ddkrt | | d||           $tlinearcC`sItj|d}t|s-tdnt|||||||S(s Compute the qth percentile of the data along the specified axis. Returns the qth percentile(s) of the array elements. Parameters ---------- a : array_like Input array or object that can be converted to an array. q : array_like of float Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive. axis : {int, tuple of int, None}, optional Axis or axes along which the percentiles are computed. The default is to compute the percentile(s) along a flattened version of the array. .. versionchanged:: 1.9.0 A tuple of axes is supported out : ndarray, optional Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary. overwrite_input : bool, optional If True, then allow the input array `a` to be modified by intermediate calculations, to save memory. In this case, the contents of the input `a` after this function completes is undefined. interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} This optional parameter specifies the interpolation method to use when the desired percentile lies between two data points ``i < j``: * 'linear': ``i + (j - i) * fraction``, where ``fraction`` is the fractional part of the index surrounded by ``i`` and ``j``. * 'lower': ``i``. * 'higher': ``j``. * 'nearest': ``i`` or ``j``, whichever is nearest. * 'midpoint': ``(i + j) / 2``. .. versionadded:: 1.9.0 keepdims : bool, optional If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array `a`. .. versionadded:: 1.9.0 Returns ------- percentile : scalar or ndarray If `q` is a single percentile and `axis=None`, then the result is a scalar. If multiple percentiles are given, first axis of the result corresponds to the percentiles. The other axes are the axes that remain after the reduction of `a`. If the input contains integers or floats smaller than ``float64``, the output data-type is ``float64``. Otherwise, the output data-type is the same as that of the input. If `out` is specified, that array is returned instead. See Also -------- mean median : equivalent to ``percentile(..., 50)`` nanpercentile quantile : equivalent to percentile, except with q in the range [0, 1]. Notes ----- Given a vector ``V`` of length ``N``, the ``q``-th percentile of ``V`` is the value ``q/100`` of the way from the minimum to the maximum in a sorted copy of ``V``. The values and distances of the two nearest neighbors as well as the `interpolation` parameter will determine the percentile if the normalized ranking does not match the location of ``q`` exactly. This function is the same as the median if ``q=50``, the same as the minimum if ``q=0`` and the same as the maximum if ``q=100``. Examples -------- >>> a = np.array([[10, 7, 4], [3, 2, 1]]) >>> a array([[10, 7, 4], [ 3, 2, 1]]) >>> np.percentile(a, 50) 3.5 >>> np.percentile(a, 50, axis=0) array([[ 6.5, 4.5, 2.5]]) >>> np.percentile(a, 50, axis=1) array([ 7., 2.]) >>> np.percentile(a, 50, axis=1, keepdims=True) array([[ 7.], [ 2.]]) >>> m = np.percentile(a, 50, axis=0) >>> out = np.zeros_like(m) >>> np.percentile(a, 50, axis=0, out=out) array([[ 6.5, 4.5, 2.5]]) >>> m array([[ 6.5, 4.5, 2.5]]) >>> b = a.copy() >>> np.percentile(b, 50, axis=1, overwrite_input=True) array([ 7., 2.]) >>> assert not np.all(a == b) The different types of interpolation can be visualized graphically: .. plot:: import matplotlib.pyplot as plt a = np.arange(4) p = np.linspace(0, 100, 6001) ax = plt.gca() lines = [ ('linear', None), ('higher', '--'), ('lower', '--'), ('nearest', '-.'), ('midpoint', '-.'), ] for interpolation, style in lines: ax.plot( p, np.percentile(a, p, interpolation=interpolation), label=interpolation, linestyle=style) ax.set( title='Interpolation methods for list: ' + str(a), xlabel='Percentile', ylabel='List item returned', yticks=a) ax.legend() plt.show() gY@s)Percentiles must be in the range [0, 100](RrR|t_quantile_is_validRit_quantile_unchecked(RtqRvRRt interpolationR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRFF s  cC`sFtj|}t|s*tdnt|||||||S(s Compute the `q`th quantile of the data along the specified axis. ..versionadded:: 1.15.0 Parameters ---------- a : array_like Input array or object that can be converted to an array. q : array_like of float Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive. axis : {int, tuple of int, None}, optional Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array. out : ndarray, optional Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary. overwrite_input : bool, optional If True, then allow the input array `a` to be modified by intermediate calculations, to save memory. In this case, the contents of the input `a` after this function completes is undefined. interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} This optional parameter specifies the interpolation method to use when the desired quantile lies between two data points ``i < j``: * linear: ``i + (j - i) * fraction``, where ``fraction`` is the fractional part of the index surrounded by ``i`` and ``j``. * lower: ``i``. * higher: ``j``. * nearest: ``i`` or ``j``, whichever is nearest. * midpoint: ``(i + j) / 2``. keepdims : bool, optional If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array `a`. Returns ------- quantile : scalar or ndarray If `q` is a single quantile and `axis=None`, then the result is a scalar. If multiple quantiles are given, first axis of the result corresponds to the quantiles. The other axes are the axes that remain after the reduction of `a`. If the input contains integers or floats smaller than ``float64``, the output data-type is ``float64``. Otherwise, the output data-type is the same as that of the input. If `out` is specified, that array is returned instead. See Also -------- mean percentile : equivalent to quantile, but with q in the range [0, 100]. median : equivalent to ``quantile(..., 0.5)`` nanquantile Notes ----- Given a vector ``V`` of length ``N``, the ``q``-th quantile of ``V`` is the value ``q`` of the way from the minimum to the maximum in a sorted copy of ``V``. The values and distances of the two nearest neighbors as well as the `interpolation` parameter will determine the quantile if the normalized ranking does not match the location of ``q`` exactly. This function is the same as the median if ``q=0.5``, the same as the minimum if ``q=0.0`` and the same as the maximum if ``q=1.0``. Examples -------- >>> a = np.array([[10, 7, 4], [3, 2, 1]]) >>> a array([[10, 7, 4], [ 3, 2, 1]]) >>> np.quantile(a, 0.5) 3.5 >>> np.quantile(a, 0.5, axis=0) array([[ 6.5, 4.5, 2.5]]) >>> np.quantile(a, 0.5, axis=1) array([ 7., 2.]) >>> np.quantile(a, 0.5, axis=1, keepdims=True) array([[ 7.], [ 2.]]) >>> m = np.quantile(a, 0.5, axis=0) >>> out = np.zeros_like(m) >>> np.quantile(a, 0.5, axis=0, out=out) array([[ 6.5, 4.5, 2.5]]) >>> m array([[ 6.5, 4.5, 2.5]]) >>> b = a.copy() >>> np.quantile(b, 0.5, axis=1, overwrite_input=True) array([ 7., 2.]) >>> assert not np.all(a == b) s%Quantiles must be in the range [0, 1](RrR RRiR(RRRvRRRR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRf s a c C`sXt|dtd|d|d|d|d|\}}|rP|j|j|S|SdS(s.Assumes that q is in [0, 1], and is an ndarrayRXRRvRRRN(Rt_quantile_ureduce_funcRwR( RRRvRRRRRRm((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR?s !cC`s|jdkr_|jdkr_xlt|jD]*}||dksT||dkr.tSq.Wn.tj|dkstj|dkrtStS(Nii gg?(RjRRR{Rrt count_nonzeroR|(RR((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRKs  *cC`sot|}|jdkr.t}|d}nt}|r^|dkrU|j}q|}n'|dkry|j}n |j}|dkrd}n|j|} || d} |dkrt | j t } n|dkrt | j t } nh|dkr&dt | t | } n?|dkrJt | j t } n|dkrYn td tjtd t} | jt kr\tj|jtjrt| d gf} n|j| d |tj||d}d}tj|jtjr+| d } tj|d dd f} n|r>| d} nt|| d |d|} n t | j t } | d}| d||| dk>> np.trapz([1,2,3]) 4.0 >>> np.trapz([1,2,3], x=[4,6,8]) 8.0 >>> np.trapz([1,2,3], dx=2) 8.0 >>> a = np.arange(6).reshape(2, 3) >>> a array([[0, 1, 2], [3, 4, 5]]) >>> np.trapz(a, axis=0) array([ 1.5, 2.5, 3.5]) >>> np.trapz(a, axis=1) array([ 2., 8.]) iiRvig@N(R RqRjRGRRwRRgR0RiRrR Rtreduce( R}RRRvRRRRRtret((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR^s,>      3 6cC`sytt|ti|g|}t|trLt||jn}t|trtt||d|djnGt|trx5|D]*}tt||d|djqWnWnt k rnXdS(s Adds documentation to obj which is in module place. If doc is a string add it to obj as a docstring If doc is a tuple, then the first element is interpreted as an attribute of obj and the second as the docstring (method, docstring) If doc is a list, then each element of the list should be a sequence of length two --> [(method1, docstring1), (method2, docstring2), ...] This routine never raises an error. This routine cannot modify read-only docstrings, as appear in new-style classes or built-in functions. Because this routine never raises an error the caller must check manually that the docstrings were changed. iiN( tgetattrt __import__tglobalsRRJR6tstripRgRt Exception(RPtobjROtnewtval((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyR`7s$' / c O`sgt|}|jdt}|jdt}|jdd}|rhtdt|dfn|d krtdnd|}gt|D]8\}}tj |j || d||d ^q} |dkr|d krd|d | d_ d|d | d _ n|s;tj d t| } n|rcg| D]}|j ^qH} n| S(s Return coordinate matrices from coordinate vectors. Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,..., xn. .. versionchanged:: 1.9 1-D and 0-D cases are allowed. Parameters ---------- x1, x2,..., xn : array_like 1-D arrays representing the coordinates of a grid. indexing : {'xy', 'ij'}, optional Cartesian ('xy', default) or matrix ('ij') indexing of output. See Notes for more details. .. versionadded:: 1.7.0 sparse : bool, optional If True a sparse grid is returned in order to conserve memory. Default is False. .. versionadded:: 1.7.0 copy : bool, optional If False, a view into the original arrays are returned in order to conserve memory. Default is True. Please note that ``sparse=False, copy=False`` will likely return non-contiguous arrays. Furthermore, more than one element of a broadcast array may refer to a single memory location. If you need to write to the arrays, make copies first. .. versionadded:: 1.7.0 Returns ------- X1, X2,..., XN : ndarray For vectors `x1`, `x2`,..., 'xn' with lengths ``Ni=len(xi)`` , return ``(N1, N2, N3,...Nn)`` shaped arrays if indexing='ij' or ``(N2, N1, N3,...Nn)`` shaped arrays if indexing='xy' with the elements of `xi` repeated to fill the matrix along the first dimension for `x1`, the second for `x2` and so on. Notes ----- This function supports both indexing conventions through the indexing keyword argument. Giving the string 'ij' returns a meshgrid with matrix indexing, while 'xy' returns a meshgrid with Cartesian indexing. In the 2-D case with inputs of length M and N, the outputs are of shape (N, M) for 'xy' indexing and (M, N) for 'ij' indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape (N, M, P) for 'xy' indexing and (M, N, P) for 'ij' indexing. The difference is illustrated by the following code snippet:: xv, yv = np.meshgrid(x, y, sparse=False, indexing='ij') for i in range(nx): for j in range(ny): # treat xv[i,j], yv[i,j] xv, yv = np.meshgrid(x, y, sparse=False, indexing='xy') for i in range(nx): for j in range(ny): # treat xv[j,i], yv[j,i] In the 1-D and 0-D case, the indexing and sparse keywords have no effect. See Also -------- index_tricks.mgrid : Construct a multi-dimensional "meshgrid" using indexing notation. index_tricks.ogrid : Construct an open multi-dimensional "meshgrid" using indexing notation. Examples -------- >>> nx, ny = (3, 2) >>> x = np.linspace(0, 1, nx) >>> y = np.linspace(0, 1, ny) >>> xv, yv = np.meshgrid(x, y) >>> xv array([[ 0. , 0.5, 1. ], [ 0. , 0.5, 1. ]]) >>> yv array([[ 0., 0., 0.], [ 1., 1., 1.]]) >>> xv, yv = np.meshgrid(x, y, sparse=True) # make sparse output arrays >>> xv array([[ 0. , 0.5, 1. ]]) >>> yv array([[ 0.], [ 1.]]) `meshgrid` is very useful to evaluate functions on a grid. >>> x = np.arange(-5, 5, 0.1) >>> y = np.arange(-5, 5, 0.1) >>> xx, yy = np.meshgrid(x, y, sparse=True) >>> z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2) >>> h = plt.contourf(x,y,z) RDtsparsetindexingtxys2meshgrid() got an unexpected keyword argument '%s'itijs.Valid values for `indexing` are 'xy' and 'ij'.iiiRg(RR(i(i(ii(ii(RhRR|R{RzRRiRRrR RwRRRD( txiRRjtcopy_RRts0RRRs((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRaZs*f    H"cC`s d }t|tk r<y |j}Wq<tk r8q<Xnt|}|j}|jjrcdnd}|d kr|dkr|j }n|j}d}n|dkrt j dt dd|r||S|j d |Snt||}td g|}|j|}t|j}t|tr^|j|\} } } t| | | } t| } | dkr|r||j d |S|j d |Sn| dkr| } | d} | dd} n||c| 8>> mask = np.ones(len(arr), dtype=bool) >>> mask[[0,2,4]] = False >>> result = arr[mask,...] Is equivalent to `np.delete(arr, [0,2,4], axis=0)`, but allows further use of `mask`. Examples -------- >>> arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) >>> arr array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]]) >>> np.delete(arr, 1, 0) array([[ 1, 2, 3, 4], [ 9, 10, 11, 12]]) >>> np.delete(arr, np.s_[::2], 1) array([[ 2, 4], [ 6, 8], [10, 12]]) >>> np.delete(arr, [1,3,5], None) array([ 1, 3, 5, 7, 8, 9, 10, 11, 12]) RtCiiis\in the future the special handling of scalars will be removed from delete and raise an errorRiRRNspin the future insert will treat boolean arrays and array-likes as boolean index instead of casting it to integers2index %i is out of bounds for axis %i with size %it same_kindsPusing a non-integer array as obj in delete will result in an error in the futurescin the future out of bounds indices will raise an error instead of being ignored by `numpy.delete`.sEin the future negative indices will not be ignored by `numpy.delete`.((RqRRt__array_wrap__RR RjtflagstfncR*RRRRDR9RRRRRRRhRRRgRRR{Rrt FutureWarningRRRR=RRt IndexErrorRtcan_castR(RRRvtwrapRjtarrordertslobjRtnewshapetstarttstoptsteptxrtnumtodelRtslobj2Rt_objt inside_boundstpositive_indices((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRbs:                          "           cC`sd}t|tk r<y |j}Wq<tk r8q<Xnt|}|j}|jjrcdnd}|dkr|dkr|j }n|j}|d}nd|dkrt j dt dd|j d|}||d <|r||S|Snt||}tdg|}|j|}t|j} t|trjt|j|itd 6} ndtj|} | jtkrt j d tdd| jt} n| jdkrtd n| jdkrs| j} | | ks| |krtd |||fn| dkr7| |7} nt|dt d|jd |j}| jdkrtj!|d|}n|j|} | |c| 7>> a = np.array([[1, 1], [2, 2], [3, 3]]) >>> a array([[1, 1], [2, 2], [3, 3]]) >>> np.insert(a, 1, 5) array([1, 5, 1, 2, 2, 3, 3]) >>> np.insert(a, 1, 5, axis=1) array([[1, 5, 1], [2, 5, 2], [3, 5, 3]]) Difference between sequence and scalars: >>> np.insert(a, [1], [[1],[2],[3]], axis=1) array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) >>> np.array_equal(np.insert(a, 1, [1, 2, 3], axis=1), ... np.insert(a, [1], [[1],[2],[3]], axis=1)) True >>> b = a.flatten() >>> b array([1, 1, 2, 2, 3, 3]) >>> np.insert(b, [2, 2], [5, 6]) array([1, 1, 5, 6, 2, 2, 3, 3]) >>> np.insert(b, slice(2, 4), [5, 6]) array([1, 1, 5, 2, 6, 2, 3, 3]) >>> np.insert(b, [2, 2], [7.13, False]) # type casting array([1, 1, 7, 0, 2, 2, 3, 3]) >>> x = np.arange(8).reshape(2, 4) >>> idx = (1, 3) >>> np.insert(x, idx, 999, axis=1) array([[ 0, 999, 1, 2, 999, 3], [ 4, 999, 5, 6, 999, 7]]) RRiis\in the future the special handling of scalars will be removed from insert and raise an errorRiR.Rsrin the future insert will treat boolean arrays and array-likes as a boolean index instead of casting it to integersDindex array argument obj to insert must be one dimensional or scalars2index %i is out of bounds for axis %i with size %iRDRuRsPusing a non-integer array as obj in insert will result in an error in the futuretkindt mergesortN((RqRRRRR RjRRR*RRRRDR9RRRRR RRRrR RRRRRiRRRR{RRRgRRhRR(RRtvaluesRvRRjRRRRRRltnumnewRRRtold_mask((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRcsX             "     $  "      cC`sht|}|dkrR|jdkr6|j}nt|}|jd}nt||fd|S(s Append values to the end of an array. Parameters ---------- arr : array_like Values are appended to a copy of this array. values : array_like These values are appended to a copy of `arr`. It must be of the correct shape (the same shape as `arr`, excluding `axis`). If `axis` is not specified, `values` can be any shape and will be flattened before use. axis : int, optional The axis along which `values` are appended. If `axis` is not given, both `arr` and `values` are flattened before use. Returns ------- append : ndarray A copy of `arr` with `values` appended to `axis`. Note that `append` does not occur in-place: a new array is allocated and filled. If `axis` is None, `out` is a flattened array. See Also -------- insert : Insert elements into an array. delete : Delete elements from an array. Examples -------- >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, 4, 5, 6, 7, 8, 9]) When `axis` is specified, `values` must have the correct shape. >>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0) array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0) Traceback (most recent call last): ... ValueError: arrays must have same number of dimensions iRvN(R RqRjR*R (RRRv((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyRd|s.   (t __future__RRRtcollections.abctabcRt ImportErrort collectionsR#RRtoperatortnumpyRrtnumpy.core.numerictcoretnumericRtt numpy.coreRRRRRRR R R R R RRRRRRRRRRRRRRtnumpy.core.umathRRRRR R!R"R#R$R%R&R'R(R)tnumpy.core.fromnumericR*R+R,R-R.R/R0tnumpy.core.numerictypesR1R2tnumpy.lib.twodim_baseR3RR4tnumpy.core.multiarrayR5R6R7R8R9R:RR;RR<Ret numpy.compatR=tnumpy.compat.py3kR>t version_infotxrangeRt __builtin__R_tnumpy.lib.histogramsR?R@t__all__RNRqRMRER{RSRRRBRARDRHRGRIRJRKRCRRORPR|RLR&Rkt_CORE_DIMENSION_LISTR%t_ARGUMENT_LISTR+R.R4R=R?RCRiRQRTRRUR\R[RZRYRRRRRR_R]RXRVRRWRRFRfRRRR^R`RaRbRcRd(((s6/tmp/pip-build-fiC0ax/numpy/numpy/lib/function_base.pyts2      "^44   V ] ~C y g 1 Vd ,8 $ 3 3 ++  "   j S b j d d     C  O  7X8g  [ #