HOME


sh-3ll 1.0
DIR:/usr/local/lib/python3.6/site-packages/xarray/core/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/xarray/core/__pycache__/npcompat.cpython-36.pyc
3

���h�"�@stdZddlZyddlmZmZmZWnJek
rndd�Zdd�Zdd	d
�Zddd�Zd
d�Z	ddd�ZYnXdS)zfFunctions copied from unreleased versions of numpy.

See the NumPy license in the licenses directory.
�N)�broadcast_to�stack�nanprodcCs4t|�t|�k	r0|jt|�d�}|jr0|j|�|S)N)�type)r�viewZ__array_finalize__)Zoriginal_arrayZ	new_array�r�4/tmp/pip-build-5_djhm0z/xray/xarray/core/npcompat.py�_maybe_view_as_subclasss

r	cCs�tj|�rt|�n|f}tj|d|d�}|r<|jr<td��tdd�|D��rVtd��tj|fddd	gd
g|dd�jd
}t	||�}|r�|j
jr�d|j
_|S)NF)�copy�subokz/cannot broadcast a non-scalar to a scalar arraycss|]}|dkVqdS)rNr)�.0�sizerrr�	<genexpr>sz _broadcast_to.<locals>.<genexpr>z4all elements of broadcast shape must be non-negativeZmulti_indexZzerosize_okZrefs_ok�readonly�C)�flagsZop_flagsZ	itershape�orderrT)�np�iterable�tuple�array�shape�
ValueError�anyZnditerZitviewsr	rZ	writeable)rrrr�	broadcast�resultrrr�
_broadcast_tos
rFcCst|||dd�S)a
Broadcast an array to a new shape.

        Parameters
        ----------
        array : array_like
            The array to broadcast.
        shape : tuple
            The shape of the desired array.
        subok : bool, optional
            If True, then sub-classes will be passed-through, otherwise
            the returned array will be forced to be a base-class array (default).

        Returns
        -------
        broadcast : array
            A readonly view on the original array with the given shape. It is
            typically not contiguous. Furthermore, more than one element of a
            broadcasted array may refer to a single memory location.

        Raises
        ------
        ValueError
            If the array is not compatible with the new shape according to NumPy's
            broadcasting rules.

        Examples
        --------
        >>> x = np.array([1, 2, 3])
        >>> np.broadcast_to(x, (3, 3))
        array([[1, 2, 3],
               [1, 2, 3],
               [1, 2, 3]])
        T)rr)r)rrrrrrr*s"rcs�dd�|D�}|std��tdd�|D��}t|�dkr@td��|djd}||kob|kns|d	j||�}t|��|dkr�||7}td
�f|tjf��fdd�|D�}tj	||d�S)
a�
        Join a sequence of arrays along a new axis.

        .. versionadded:: 1.10.0

        Parameters
        ----------
        arrays : sequence of ndarrays
            Each array must have the same shape.
        axis : int, optional
            The axis along which the arrays will be stacked.

        Returns
        -------
        stacked : ndarray
            The stacked array has one more dimension than the input arrays.
        See Also
        --------
        concatenate : Join a sequence of arrays along an existing axis.
        split : Split array into a list of multiple sub-arrays of equal size.

        Examples
        --------
        >>> arrays = [np.random.randn(3, 4) for _ in range(10)]
        >>> np.stack(arrays, axis=0).shape
        (10, 3, 4)

        >>> np.stack(arrays, axis=1).shape
        (3, 10, 4)

        >>> np.stack(arrays, axis=2).shape
        (3, 4, 10)

        >>> a = np.array([1, 2, 3])
        >>> b = np.array([2, 3, 4])
        >>> np.stack((a, b))
        array([[1, 2, 3],
               [2, 3, 4]])

        >>> np.stack((a, b), axis=-1)
        array([[1, 2],
               [2, 3],
               [3, 4]])
        cSsg|]}tj|��qSr)rZ
asanyarray)r�arrrrr�
<listcomp>|szstack.<locals>.<listcomp>z need at least one array to stackcss|]}|jVqdS)N)r)rrrrrr�szstack.<locals>.<genexpr>�z)all input arrays must have the same shaperz"axis {0} out of bounds [-{1}, {1})Ncsg|]}|��qSrr)rr)�slrrr�s)�axis)
r�set�len�ndim�format�
IndexError�slicerZnewaxisZconcatenate)Zarraysr!ZshapesZresult_ndim�msgZexpanded_arraysr)r rrOs-rcCsht|tj�}|rtj|�}t|jjtj�s4|dfS|sFtj|dd�}tj|�}tj	|||d�||fS)a�
        If `a` is of inexact type, make a copy of `a`, replace NaNs with
        the `val` value, and return the copy together with a boolean mask
        marking the locations where NaNs were present. If `a` is not of
        inexact type, do nothing and return `a` together with a mask of None.

        Note that scalars will end up as array scalars, which is important
        for using the result as the value of the out argument in some
        operations.

        Parameters
        ----------
        a : array-like
            Input array.
        val : float
            NaN values are set to val before doing the operation.

        Returns
        -------
        y : ndarray
            If `a` is of inexact type, return a copy of `a` with the NaNs
            replaced by the fill value, otherwise return `a`.
        mask: {bool, None}
            If `a` is of inexact type, return a boolean mask marking locations of
            NaNs, otherwise return None.

        NT)r)�where)
�
isinstancerZndarrayr�
issubclass�dtyperZinexact�isnanZcopyto)�a�valZis_new�maskrrr�_replace_nan�s

r1cCs"t|d�\}}tj|||||d�S)a�	
        Return the product of array elements over a given axis treating Not a
        Numbers (NaNs) as zero.

        One is returned for slices that are all-NaN or empty.

        .. versionadded:: 1.10.0

        Parameters
        ----------
        a : array_like
            Array containing numbers whose sum is desired. If `a` is not an
            array, a conversion is attempted.
        axis : int, optional
            Axis along which the product is computed. The default is to compute
            the product of the flattened array.
        dtype : data-type, optional
            The type of the returned array and of the accumulator in which the
            elements are summed.  By default, the dtype of `a` is used.  An
            exception is when `a` has an integer type with less precision than
            the platform (u)intp. In that case, the default will be either
            (u)int32 or (u)int64 depending on whether the platform is 32 or 64
            bits. For inexact inputs, dtype must be inexact.
        out : ndarray, optional
            Alternate output array in which to place the result.  The default
            is ``None``. If provided, it must have the same shape as the
            expected output, but the type will be cast if necessary.  See
            `doc.ufuncs` for details. The casting of NaN to integer can yield
            unexpected results.
        keepdims : bool, optional
            If 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 `arr`.

        Returns
        -------
        y : ndarray or numpy scalar

        See Also
        --------
        numpy.prod : Product across array propagating NaNs.
        isnan : Show which elements are NaN.

        Notes
        -----
        Numpy integer arithmetic is modular. If the size of a product exceeds
        the size of an integer accumulator, its value will wrap around and the
        result will be incorrect. Specifying ``dtype=double`` can alleviate
        that problem.

        Examples
        --------
        >>> np.nanprod(1)
        1
        >>> np.nanprod([1])
        1
        >>> np.nanprod([1, np.nan])
        1.0
        >>> a = np.array([[1, 2], [3, np.nan]])
        >>> np.nanprod(a)
        6.0
        >>> np.nanprod(a, axis=0)
        array([ 3.,  2.])

        r)r!r,�out�keepdims)r1r�prod)r.r!r,r2r3r0rrrr�sBr)F)r)NNNr)
�__doc__Znumpyrrrr�ImportErrorr	rr1rrrr�<module>s

%
A*