numpy排序、搜索和计数函数和方法

numpy排序、搜索和计数函数和方法:

排序Sorting

sort(a[, axis, kind, order]) Return a sorted copy of an array.
lexsort(keys[, axis]) Perform an indirect sort using a sequence of keys.
argsort(a[, axis, kind, order]) Returns the indices that would sort an array.
ndarray.sort([axis, kind, order]) Sort an array, in-place.
msort(a) Return a copy of an array sorted along the first axis.
sort_complex(a) Sort a complex array using the real part first, then the imaginary part.
partition(a, kth[, axis, kind, order]) Return a partitioned copy of an array.
argpartition(a, kth[, axis, kind, order]) Perform an indirect partition along the given axis using the algorithm specified by the kind keyword.

python列表排序

list.sort()一般用法:list.sort(axis = None, key=lambdax:x[1],reverse True)

或者使用内置函数sorted():

sorted(data.tolist(), key=lambda x: x[split])

[python函数: 内置函数]

用ndarray.sort内建函数排序

数组的sort()方法用于对数组进行排序,它将改变数组的内容。

ndarray.sort()没有key参数,那怎么编写比较函数comparator?

示例

list1 = [[1, 3, 2], [3, 5, 4]]
array = numpy.array(list1)
array.sort(axis=1)
print(array)

[[1 2 3]
 [3 4 5]]

sort内建函数是就地排序,会改变原有数组,不同于Python中自带的sorted函数和numpy.sort通用函数,参数也不一样。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值