Current File : //proc/self/root/proc/self/root/lib64/python2.7/site-packages/numpy/lib/arraysetops.pyo |
�
E�`Qc @ s� d Z d d d d d d d g Z d d l Z d d
l m Z d d d � Z e e d � Z e d
� Z
e d � Z e d � Z d � Z
e d � Z d S( s
Set operations for 1D numeric arrays based on sorting.
:Contains:
ediff1d,
unique,
intersect1d,
setxor1d,
in1d,
union1d,
setdiff1d
:Notes:
For floating point arrays, inaccurate results may appear due to usual round-off
and floating point comparison issues.
Speed could be gained in some operations by an implementation of
sort(), that can provide directly the permutation vectors, avoiding
thus calls to argsort().
To do: Optionally return indices analogously to unique for all functions.
:Author: Robert Cimrman
t ediff1dt intersect1dt setxor1dt union1dt setdiff1dt uniquet in1di����N( t deprecatec C s� t j | � j } | d | d } | g } | d k rL | j d | � n | d k rh | j | � n t | � d k r� t j | � } n | S( s?
The differences between consecutive elements of an array.
Parameters
----------
ary : array_like
If necessary, will be flattened before the differences are taken.
to_end : array_like, optional
Number(s) to append at the end of the returned differences.
to_begin : array_like, optional
Number(s) to prepend at the beginning of the returned differences.
Returns
-------
ediff1d : ndarray
The differences. Loosely, this is ``ary.flat[1:] - ary.flat[:-1]``.
See Also
--------
diff, gradient
Notes
-----
When applied to masked arrays, this function drops the mask information
if the `to_begin` and/or `to_end` parameters are used.
Examples
--------
>>> x = np.array([1, 2, 4, 7, 0])
>>> np.ediff1d(x)
array([ 1, 2, 3, -7])
>>> np.ediff1d(x, to_begin=-99, to_end=np.array([88, 99]))
array([-99, 1, 2, 3, -7, 88, 99])
The returned array is always 1D.
>>> y = [[1, 2, 4], [1, 6, 24]]
>>> np.ediff1d(y)
array([ 1, 2, -3, 5, 18])
i i����i N( t npt
asanyarrayt flatt Nonet insertt appendt lent hstack( t aryt to_endt to_begint edt arrays( ( s; /usr/lib64/python2.7/site-packages/numpy/lib/arraysetops.pyR s + c C s� y | j � } WnS t k
re | rM | rM t t | � � } t j | � St j | � j � } n X| j d k r� | r� | r� | t j d t j � t j d t j � f S| s� | r� | t j d t j � f S| Sn | s� | r�| r� | j
d d � } n | j
� } | | } t j t g | d | d k f � } | r�t j
| � d } | j
� } | r| | | | | | f S| | | | f Sq�| | | | f Sn8 | j � t j t g | d | d k f � } | | Sd S( sE
Find the unique elements of an array.
Returns the sorted unique elements of an array. There are two optional
outputs in addition to the unique elements: the indices of the input array
that give the unique values, and the indices of the unique array that
reconstruct the input array.
Parameters
----------
ar : array_like
Input array. This will be flattened if it is not already 1-D.
return_index : bool, optional
If True, also return the indices of `ar` that result in the unique
array.
return_inverse : bool, optional
If True, also return the indices of the unique array that can be used
to reconstruct `ar`.
Returns
-------
unique : ndarray
The sorted unique values.
unique_indices : ndarray, optional
The indices of the first occurrences of the unique values in the
(flattened) original array. Only provided if `return_index` is True.
unique_inverse : ndarray, optional
The indices to reconstruct the (flattened) original array from the
unique array. Only provided if `return_inverse` is True.
See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.
Examples
--------
>>> np.unique([1, 1, 2, 2, 3, 3])
array([1, 2, 3])
>>> a = np.array([[1, 1], [2, 3]])
>>> np.unique(a)
array([1, 2, 3])
Return the indices of the original array that give the unique values:
>>> a = np.array(['a', 'b', 'b', 'c', 'a'])
>>> u, indices = np.unique(a, return_index=True)
>>> u
array(['a', 'b', 'c'],
dtype='|S1')
>>> indices
array([0, 1, 3])
>>> a[indices]
array(['a', 'b', 'c'],
dtype='|S1')
Reconstruct the input array from the unique values:
>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
>>> u, indices = np.unique(a, return_inverse=True)
>>> u
array([1, 2, 3, 4, 6])
>>> indices
array([0, 1, 4, 3, 1, 2, 1])
>>> u[indices]
array([1, 2, 6, 4, 2, 3, 2])
i t kindt mergesorti i����N( t flattent AttributeErrort sortedt setR t asarrayR t sizet emptyt boolt argsortt concatenatet Truet cumsumt sort( t art return_indext return_inverset itemst permt auxt flagt iflagt iperm( ( s; /usr/lib64/python2.7/site-packages/numpy/lib/arraysetops.pyR Z s: E
+
&
&c C sZ | s! t | � } t | � } n t j | | f � } | j � | d | d | d k S( s�
Find the intersection of two arrays.
Return the sorted, unique values that are in both of the input arrays.
Parameters
----------
ar1, ar2 : array_like
Input arrays.
assume_unique : bool
If True, the input arrays are both assumed to be unique, which
can speed up the calculation. Default is False.
Returns
-------
intersect1d : ndarray
Sorted 1D array of common and unique elements.
See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.
Examples
--------
>>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1])
array([1, 3])
i����i ( R R R R# ( t ar1t ar2t
assume_uniqueR) ( ( s; /usr/lib64/python2.7/site-packages/numpy/lib/arraysetops.pyR � s
c C s� | s! t | � } t | � } n t j | | f � } | j d k rI | S| j � t j t g | d | d k t g f � } | d | d k } | | S( s�
Find the set exclusive-or of two arrays.
Return the sorted, unique values that are in only one (not both) of the
input arrays.
Parameters
----------
ar1, ar2 : array_like
Input arrays.
assume_unique : bool
If True, the input arrays are both assumed to be unique, which
can speed up the calculation. Default is False.
Returns
-------
setxor1d : ndarray
Sorted 1D array of unique values that are in only one of the input
arrays.
Examples
--------
>>> a = np.array([1, 2, 3, 2, 4])
>>> b = np.array([2, 3, 5, 7, 5])
>>> np.setxor1d(a,b)
array([1, 4, 5, 7])
i i i����( R R R R R# R! ( R- R. R/ R) R* t flag2( ( s; /usr/lib64/python2.7/site-packages/numpy/lib/arraysetops.pyR � s
,c C sW t j | � j � } t j | � j � } t | � d t | � d k r� t j t | � d t j �} x | D] } | | | k O} qo W| S| s� t j | d t �\ } } t j | � } n t j | | f � } | j d d � } | | } | d | d k } t j | t
g f � }
| j d d � t | � } | rG|
| S|
| | Sd S(
s
Test whether each element of a 1-D array is also present in a second array.
Returns a boolean array the same length as `ar1` that is True
where an element of `ar1` is in `ar2` and False otherwise.
Parameters
----------
ar1 : (M,) array_like
Input array.
ar2 : array_like
The values against which to test each value of `ar1`.
assume_unique : bool, optional
If True, the input arrays are both assumed to be unique, which
can speed up the calculation. Default is False.
Returns
-------
in1d : (M,) ndarray, bool
The values `ar1[in1d]` are in `ar2`.
See Also
--------
numpy.lib.arraysetops : Module with a number of other functions for
performing set operations on arrays.
Notes
-----
`in1d` can be considered as an element-wise function version of the
python keyword `in`, for 1-D sequences. ``in1d(a, b)`` is roughly
equivalent to ``np.array([item in b for item in a])``.
.. versionadded:: 1.4.0
Examples
--------
>>> test = np.array([0, 1, 2, 5, 0])
>>> states = [0, 2]
>>> mask = np.in1d(test, states)
>>> mask
array([ True, False, True, False, True], dtype=bool)
>>> test[mask]
array([0, 2, 0])
i
g��(\��?t dtypeR&