當前位置: 首頁>>代碼示例>>Python>>正文


Python ndarray.sort方法代碼示例

本文整理匯總了Python中numpy.ndarray.sort方法的典型用法代碼示例。如果您正苦於以下問題:Python ndarray.sort方法的具體用法?Python ndarray.sort怎麽用?Python ndarray.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.ndarray的用法示例。


在下文中一共展示了ndarray.sort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sort

# 需要導入模塊: from numpy import ndarray [as 別名]
# 或者: from numpy.ndarray import sort [as 別名]
def sort(a, axis=-1, kind='quicksort', order=None, endwith=True, fill_value=None):
    "Function version of the eponymous method."
    a = narray(a, copy=True, subok=True)
    if axis is None:
        a = a.flatten()
        axis = 0
    if fill_value is None:
        if endwith:
            # nan > inf
            if np.issubdtype(a.dtype, np.floating):
                filler = np.nan
            else:
                filler = minimum_fill_value(a)
        else:
            filler = maximum_fill_value(a)
    else:
        filler = fill_value

    sindx = filled(a, filler).argsort(axis=axis, kind=kind, order=order)

    # save meshgrid memory for 1d arrays
    if a.ndim == 1:
        indx = sindx
    else:
        indx = np.meshgrid(*[np.arange(x) for x in a.shape], sparse=True,
                           indexing='ij')
        indx[axis] = sindx
    return a[indx] 
開發者ID:amoose136,項目名稱:radar,代碼行數:30,代碼來源:core.py

示例2: argsort

# 需要導入模塊: from numpy import ndarray [as 別名]
# 或者: from numpy.ndarray import sort [as 別名]
def argsort(self, axis=None, kind='quicksort', order=None, fill_value=None):
        """
        Return an ndarray of indices that sort the array along the
        specified axis.  Masked values are filled beforehand to
        `fill_value`.

        Parameters
        ----------
        axis : int, optional
            Axis along which to sort.  The default is -1 (last axis).
            If None, the flattened array is used.
        fill_value : var, optional
            Value used to fill the array before sorting.
            The default is the `fill_value` attribute of the input array.
        kind : {'quicksort', 'mergesort', 'heapsort'}, optional
            Sorting algorithm.
        order : list, optional
            When `a` is an array with fields defined, this argument specifies
            which fields to compare first, second, etc.  Not all fields need be
            specified.

        Returns
        -------
        index_array : ndarray, int
            Array of indices that sort `a` along the specified axis.
            In other words, ``a[index_array]`` yields a sorted `a`.

        See Also
        --------
        sort : Describes sorting algorithms used.
        lexsort : Indirect stable sort with multiple keys.
        ndarray.sort : Inplace sort.

        Notes
        -----
        See `sort` for notes on the different sorting algorithms.

        Examples
        --------
        >>> a = np.ma.array([3,2,1], mask=[False, False, True])
        >>> a
        masked_array(data = [3 2 --],
                     mask = [False False  True],
               fill_value = 999999)
        >>> a.argsort()
        array([1, 0, 2])

        """
        if fill_value is None:
            fill_value = default_fill_value(self)
        d = self.filled(fill_value).view(ndarray)
        return d.argsort(axis=axis, kind=kind, order=order) 
開發者ID:amoose136,項目名稱:radar,代碼行數:54,代碼來源:core.py


注:本文中的numpy.ndarray.sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。