from numpy\core_multiarray_umath.py

@array_function_from_c_func_and_dispatcher(_multiarray_umath.lexsort)
def lexsort(keys, axis=None):"""lexsort(keys, axis=-1)Perform an indirect stable sort using a sequence of keys.使用键序列执行间接稳定排序。Given multiple sorting keys, which can be interpreted as columns in a spreadsheet, lexsort returns an array of integer indices that describes the sort order by multiple columns. The last key in the sequence is used for the primary sort order, the second-to-last key for the secondary sort order, and so on. The keys argument must be a sequence of objects that can be converted to arrays of the same shape. If a 2D array is provided for the keys argument, it's rows are interpreted as the sorting keys and sorting is according to the last row, second last row etc.给定多个排序键(可以将其解释为电子表格中的列),lexsort返回一个整数索引数组,该数组描述按多个列排序的顺序。 序列中的最后一个键用于主排序顺序,倒数第二个键用于辅助排序顺序,依此类推。 keys参数必须是可以转换为相同形状的数组的对象序列。 如果为keys参数提供了2D数组,则将其行解释为排序键,并根据最后一行,倒数第二行等进行排序。Parameters----------keys : (k, N) array or tuple containing k (N,)-shaped sequencesThe `k` different "columns" to be sorted.  The last column (or row if `keys` is a 2D array) is the primary sort key.(k,N)个包含k(N,)形序列的数组或元组要排序的k个不同的“列”。 最后一列(如果keys是2D数组,则为行)是主排序键。axis : int, optionalAxis to be indirectly sorted.  By default, sort over the last axis.要间接排序的轴。 默认情况下,对最后一个轴进行排序。Returns-------indices : (N,) ndarray of intsArray of indices that sort the keys along the specified axis.(N,)个整数的ndarray沿指定轴对键进行排序的索引数组。See Also--------argsort : Indirect sort.ndarray.sort : In-place sort.sort : Return a sorted copy of an array.Examples--------Sort names: first by surname, then by name.对名称进行排序:首先按姓氏,然后按名称。(就是如果姓氏相同,就按名称排)>>> surnames =    ('Hertz',    'Galilei', 'Hertz')>>> first_names = ('Heinrich', 'Galileo', 'Gustav')>>> ind = np.lexsort((first_names, surnames))>>> indarray([1, 2, 0])>>> [surnames[i] + ", " + first_names[i] for i in ind]['Galilei, Galileo', 'Hertz, Gustav', 'Hertz, Heinrich']Sort two columns of numbers:对两列数字进行排序:>>> a = [1,5,1,4,3,4,4] # First column>>> b = [9,4,0,4,0,2,1] # Second column>>> ind = np.lexsort((b,a)) # Sort by a, then by b>>> indarray([2, 0, 4, 6, 5, 3, 1])>>> [(a[i],b[i]) for i in ind][(1, 0), (1, 9), (3, 0), (4, 1), (4, 2), (4, 4), (5, 4)]Note that sorting is first according to the elements of ``a``.Secondary sorting is according to the elements of ``b``.请注意,排序首先是根据``a''的元素进行的。二级排序是根据``b''的元素进行的。A normal ``argsort`` would have yielded:正常的``argsort''会产生:>>> [(a[i],b[i]) for i in np.argsort(a)][(1, 9), (1, 0), (3, 0), (4, 4), (4, 2), (4, 1), (5, 4)]Structured arrays are sorted lexically by ``argsort``:>>> x = np.array([(1,9), (5,4), (1,0), (4,4), (3,0), (4,2), (4,1)],...              dtype=np.dtype([('x', int), ('y', int)]))>>> np.argsort(x) # or np.argsort(x, order=('x', 'y'))array([2, 0, 4, 6, 5, 3, 1])"""if isinstance(keys, tuple):return keyselse:return (keys,)

示例:

# -*- coding: utf-8 -*-
"""
@File    : plot.py
@Time    : 2020/2/24 8:55
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""import matplotlib.pyplot as pltimport numpy as np# 如发现格式不对可用记事本或notepad批量替换
keyword = {'11:30.0': (50000, 13.96), '12:16.0': (54500, 13.20), '13:15.0': (47500, 12.48),'14:22.0': (55450, 12.44), '14:35.0': (55430, 13.72), '17:03.0': (13990, 11.00),'17:38.0': (9058, 11.60), '17:57.0': (5044, 12.46), '18:20.0': (1300, 13.80),'18:25.0': (900, 13.90), '18:28.0': (700, 13.96), '18:40.0': (200, 13.34),'18:42.0': (150, 13.10), '18:44.0': (100, 11.80), '18:44.2': (90, 11.34),'18.44.4': (80, 11.38), '18:44.8': (70, 9.50), '18:45.0': (60, 9.20),'18:46.0': (50, 11.9), '18:46.3': (40, 10.8), '18:46.6': (30, 9.20),'18:49.0': (20, 9.70), '18:49.6': (15, 6.90), '18:50.3': (13, 4.70),'18:50.9': (12, 3.80), '18:51.5': (11, 2.60), '18:52.2': (10, 1.70),'18:52.9': (9, 1.00), '18:53.6': (8, 0.2), '18:54.3': (7, 0.06),'18:55.0': (6, 0.02)}data = []for key in keyword:data.append(keyword[key])data = np.array(data)
# print(data)
# [[5.000e+04 1.396e+01]
#  [5.450e+04 1.320e+01]
#  [4.750e+04 1.248e+01]
#  [5.545e+04 1.244e+01]
#  [5.543e+04 1.372e+01]
#  [1.399e+04 1.100e+01]
#  [9.058e+03 1.160e+01]
#  [5.044e+03 1.246e+01]
#  [1.300e+03 1.380e+01]
#  [9.000e+02 1.390e+01]
#  [7.000e+02 1.396e+01]
#  [2.000e+02 1.334e+01]
#  [1.500e+02 1.310e+01]
#  [1.000e+02 1.180e+01]
#  [9.000e+01 1.134e+01]
#  [8.000e+01 1.138e+01]
#  [7.000e+01 9.500e+00]
#  [6.000e+01 9.200e+00]
#  [5.000e+01 1.190e+01]
#  [4.000e+01 1.080e+01]
#  [3.000e+01 9.200e+00]
#  [2.000e+01 9.700e+00]
#  [1.500e+01 6.900e+00]
#  [1.300e+01 4.700e+00]
#  [1.200e+01 3.800e+00]
#  [1.100e+01 2.600e+00]
#  [1.000e+01 1.700e+00]
#  [9.000e+00 1.000e+00]
#  [8.000e+00 2.000e-01]
#  [7.000e+00 6.000e-02]
#  [6.000e+00 2.000e-02]]x = data[:, 0]
# print(x)
# [5.000e+04 5.450e+04 4.750e+04 5.545e+04 5.543e+04 1.399e+04 9.058e+03
#  5.044e+03 1.300e+03 9.000e+02 7.000e+02 2.000e+02 1.500e+02 1.000e+02
#  9.000e+01 8.000e+01 7.000e+01 6.000e+01 5.000e+01 4.000e+01 3.000e+01
#  2.000e+01 1.500e+01 1.300e+01 1.200e+01 1.100e+01 1.000e+01 9.000e+00
#  8.000e+00 7.000e+00 6.000e+00]
y = data[:, 1]
# print(y)
# [13.96 13.2  12.48 12.44 13.72 11.   11.6  12.46 13.8  13.9  13.96 13.34
#  13.1  11.8  11.34 11.38  9.5   9.2  11.9  10.8   9.2   9.7   6.9   4.7
#   3.8   2.6   1.7   1.    0.2   0.06  0.02]ind = np.lexsort((x,))
# print(ind)
# [30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7
#   6  5  2  0  1  4  3]data_sort = [(x[i], y[i]) for i in ind]# print(data_sort)
# [(6.0, 0.02), (7.0, 0.06), (8.0, 0.2), (9.0, 1.0), (10.0, 1.7), (11.0, 2.6), (12.0, 3.8), (13.0, 4.7), (15.0, 6.9), (20.0, 9.7), (30.0, 9.2), (40.0, 10.8), (50.0, 11.9), (60.0, 9.2), (70.0, 9.5), (80.0, 11.38), (90.0, 11.34), (100.0, 11.8), (150.0, 13.1), (200.0, 13.34), (700.0, 13.96), (900.0, 13.9), (1300.0, 13.8), (5044.0, 12.46), (9058.0, 11.6), (13990.0, 11.0), (47500.0, 12.48), (50000.0, 13.96), (54500.0, 13.2), (55430.0, 13.72), (55450.0, 12.44)]x_sort, y_sort = np.array(data_sort)[:, 0], np.array(data_sort)[:, 1]# 用3次多项式拟合  可以改为5 次多项式。。。。 返回三次多项式系数
z1 = np.polyfit(x_sort, y_sort, 5)
p1 = np.poly1d(z1)# 在屏幕上打印拟合多项式
print(p1)
#            3             2
# 2.534e-13 x - 2.506e-08 x + 0.000714 x + 7.821# 设置绘制间隔
x_lin = np.arange(0, 60000, 5)yvals = p1(x_lin)  # 也可以使用yvals=np.polyval(z1,x)plot1 = plt.plot(x_sort, y_sort, '*', label='original values')
plot2 = plt.plot(x_lin, yvals, 'r', label='polyfit values')# 限制绘制上下限
plt.ylim(0, 16)plt.xlabel('Illumination/lm')plt.ylabel('Detect num/pcs')plt.legend(loc=4)  # 指定legend的位置,读者可以自己help它的用法plt.title('polyfitting')plt.show()plt.savefig('p1.png')


参考文章:python numpy np.argsort()(返回将对数组进行排序的索引)(不懂区别?)

python numpy np.lexsort()(使用键序列执行间接稳定排序)(具体没太搞懂区别?)相关推荐

  1. python numpy np.argsort()(返回将对数组进行排序的索引)(不懂区别?)

    from numpy\core\fromnumeric.py @array_function_dispatch(_argsort_dispatcher) def argsort(a, axis=-1, ...

  2. (python numpy) np.array.shape 中 (3,)、(3,1)、(1,3)的区别

    (python numpy) np.array.shape 中 (3,).(3,1).(1,3)的区别 被人问到这个问题,就记录一下吧 1. (3,) (3,)是[x,y,z][x,y,z][x,y, ...

  3. python numpy 获得数组的行和列(三种方法)

    通过shape属性获得 首先是用 shape 这个属性,学numpy的时候,知道,ndarray有shape这个属性,返回一个元组,里面放了每个维度的大小,所以直接就能想到,对于二维数组 print( ...

  4. 怎么用Python写出随时间变化的字_面试必备 | 带你彻底搞懂 Python 生成器

    文章转载地址:面试必备 | 带你彻底搞懂 Python 生成器. 写在之前 Python 的高级语言特性一直是我们学习 Python 的一个难点,大部分人并没有做到熟练的掌握,甚至去学习它都感觉很困难 ...

  5. python numpy np.fromstring()函数(从字符串文本中提取数字,返回一维数组)(爬虫提取数字挺好用的)

    from numpy\core\multiarray.py def fromstring(string, dtype=None, count=-1, sep=''): # real signature ...

  6. python numpy np.finfo()函数 eps

    用法 finfo函数是根据括号中的类型来获得信息,获得符合这个类型的数型 例1: import numpy as np a=np.array([[1],[2],[-1],[0]]) b=np.maxi ...

  7. [转载] python numpy np.finfo()函数 eps

    参考链接: Python中的numpy.log2 用法 finfo函数是根据括号中的类型来获得信息,获得符合这个类型的数型 例1: import numpy as np a=np.array([[1] ...

  8. [转载] python numpy np.exp()函数

    参考链接: Python中的numpy.exp def exp(x, *args, **kwargs): # real signature unknown; NOTE: unreliably rest ...

  9. python numpy np.convolve()函数(返回两个一维序列的离散线性卷积)

    文章目录 from numpy.core.numeric() 计算流程 from numpy.core.numeric() def convolve(a, v, mode='full'):" ...

最新文章

  1. 最详细的maven教程,可以收藏!
  2. DELL 通过iDrac安装ESXI
  3. HDU-3743 Minimum Sum,划分树模板
  4. Entity Framework教程
  5. DataScience:深入探讨与分析机器学习中的数据处理之非线性变换—log对数变换、sigmoid/softmax变换
  6. opeansea, nft, trend
  7. Flutter 弧度与角度之间的换算
  8. Vivado使用ILA调试报错解决
  9. html 折叠焦点图切换,jQuery层叠式图片切换焦点图插件
  10. 输出矩阵的左下半三角
  11. 2021亚太杯数学建模C题全网成品论文+代码+详细思路+数据+参考文献
  12. 传送带计数器c语言程序,脉搏计数器的程序(用C语言编写程序)
  13. wow插件初级基础知识及安装指南
  14. EDTA 最简易安装方法
  15. 超宽带雷达P440?雷达的快时间慢时间是什么意思?
  16. 哈夫曼树中压缩率到底是什么意思
  17. 金簿财务软件智能版3.985
  18. 密码学归约证明——定长对称加密密钥的敌手不可区分性
  19. Struts2 ValueStack ActionContext OGNL 关系
  20. 我们为什么要将图片转换成PDF?

热门文章

  1. ★ 让你的虚机飞起来 ★
  2. 【学习笔记】JS进阶语法一DOM进阶
  3. 【转载】字段符号在ABAP OOP中的应用
  4. 【学习笔记】23、读写文件(I/O操作)— 写文件
  5. 【力荐】Select查询语句中LIKE关键词的优化方法分析
  6. ALEIDoc EDI(5)--Inbound Function
  7. OBYC中的GBB一般修改的解释
  8. 生产订单修改记录的跟踪方法!
  9. BAPI_CONTRACT_CREATE
  10. ABAP中的动态运算函数