排序,搜索和计数速查表

排序搜索集合速查表

排序

  • numpy.sort(a[, axis=-1, kind='quicksort', order=None]) Return a sorted copy of an array.

    • axis:排序沿数组的(轴)方向,0表示按行,1表示按列,None表示展开来排序,默认为-1,表示沿最后的轴排序。
    • kind:排序的算法,提供了快排’quicksort’、混排’mergesort’、堆排’heapsort’, 默认为‘quicksort’。
    • order:排序的字段名,可指定字段排序,默认为None。
  • numpy.argsort(a[, axis=-1, kind='quicksort', order=None]) Returns the indices that would sort an array.

  • numpy.lexsort(keys[, axis=-1]) Perform an indirect stable sort using a sequence of keys.(使用键序列执行间接稳定排序。)

  • numpy.partition(a, kth, axis=-1, kind='introselect', order=None) Return a partitioned copy of an array.

  • numpy.argpartition(a, kth, axis=-1, kind='introselect', order=None)

搜索

  • numpy.argmax(a[, axis=None, out=None])Returns the indices of the maximum values along an axis.

  • numpy.argmin(a[, axis=None, out=None])Returns the indices of the minimum values along an axis.

  • numppy.nonzero(a) Return the indices of the elements that are non-zero.

  • numpy.where(condition, [x=None, y=None]) Return elements chosen from x or y depending on condition.

  • numpy.searchsorted(a, v[, side='left', sorter=None]) Find indices where elements should be inserted to maintain order.

    • a:一维输入数组。当sorter参数为None的时候,a必须为升序数组;否则,sorter不能为空,存放a中元素的index,用于反映a数组的升序排列方式。
    • v:插入a数组的值,可以为单个元素,list或者ndarray
    • side:查询方向,当为left时,将返回第一个符合条件的元素下标;当为right时,将返回最后一个符合条件的元素下标。
    • sorter:一维数组存放a数组元素的 index,index 对应元素为升序。
  • numpy.count_nonzero(a, axis=None) Counts the number of non-zero values in the array a.

    扫描二维码关注公众号,回复: 12419286 查看本文章

集合

  • numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None) Find the unique elements of an array.

    • return_index=True 表示返回新列表元素在旧列表中的位置。
    • return_inverse=True表示返回旧列表元素在新列表中的位置。
    • return_counts=True表示返回新列表元素在旧列表中出现的次数。
  • numpy.in1d(ar1, ar2, assume_unique=False, invert=False) Test whether each element of a 1-D array is also present in a second array.

  • numpy.intersect1d(ar1, ar2, assume_unique=False, return_indices=False) Find the intersection of two arrays.

  • numpy.union1d(ar1, ar2) Find the union of two arrays.

  • numpy.setdiff1d(ar1, ar2, assume_unique=False) Find the set difference of two arrays.

  • setxor1d(ar1, ar2, assume_unique=False) Find the set exclusive-or of two arrays.

猜你喜欢

转载自blog.csdn.net/weixin_41545602/article/details/109409636
今日推荐