当前位置: 首页 > news >正文

唐山有制作网站的没百度推广后台

唐山有制作网站的没,百度推广后台,手机网站源码 html5,查询网站收录命令1 NumPy 排序、条件筛选函数 NumPy 提供了多种排序的方法。 这些排序函数实现不同的排序算法,每个排序算法的特征在于执行速度,最坏情况性能,所需的工作空间和算法的稳定性。 下表显示了三种排序算法的比较。 种类速度最坏情况工作空间稳定性…

1 NumPy 排序、条件筛选函数

        NumPy 提供了多种排序的方法。 这些排序函数实现不同的排序算法,每个排序算法的特征在于执行速度,最坏情况性能,所需的工作空间和算法的稳定性。 下表显示了三种排序算法的比较。

种类速度最坏情况工作空间稳定性
'quicksort'(快速排序)1O(n^2)0
'mergesort'(归并排序)2O(n*log(n))~n/2
'heapsort'(堆排序)3O(n*log(n))0

1.1 numpy.sort()

        numpy.sort() 函数返回输入数组的排序副本。函数格式如下:

numpy.sort(a, axis, kind, order)
  • a: 要排序的数组
  • axis: 沿着它排序数组的轴,如果没有数组会被展开,沿着最后的轴排序, axis=0 按列排序,axis=1 按行排序
  • kind: 默认为'quicksort'(快速排序)
  • order: 如果数组包含字段,则是要排序的字段
import numpy as npa = np.array([[3, 7], [9, 1]])
print('我们的数组是:')
print(a)
print('\n')
print('调用 sort() 函数:')
print(np.sort(a))
print('\n')
print('按列排序:')
print(np.sort(a, axis=0))
print('\n')
# 在 sort 函数中排序字段
dt = np.dtype([('name', 'S10'), ('age', int)])
a = np.array([("raju", 21), ("anil", 25), ("ravi", 17), ("amar", 27)], dtype=dt)
print('我们的数组是:')
print(a)
print('\n')
print('按 name 排序:')
print(np.sort(a, order='name'))

1.2 numpy.argsort()

        numpy.argsort() 函数返回的是数组值从小到大的索引值。

import numpy as npx = np.array([3, 1, 2])
print('我们的数组是:')
print(x)
print('\n')
print('对 x 调用 argsort() 函数:')
y = np.argsort(x)
print(y)
print('\n')
print('以排序后的顺序重构原数组:')
print(x[y])
print('\n')
print('使用循环重构原数组:')
for i in y:print(x[i], end=" ")

1.3 numpy.lexsort()

        numpy.lexsort() 用于对多个序列进行排序。把它想象成对电子表格进行排序,每一列代表一个序列,排序时优先照顾靠后的列。这里举一个应用场景:小升初考试,重点班录取学生按照总成绩录取。在总成绩相同时,数学成绩高的优先录取,在总成绩和数学成绩都相同时,按照英语成绩录取…… 这里,总成绩排在电子表格的最后一列,数学成绩在倒数第二列,英语成绩在倒数第三列。

import numpy as npnm = ('raju', 'anil', 'ravi', 'amar')
dv = ('f.y.', 's.y.', 's.y.', 'f.y.')
ind = np.lexsort((dv, nm))
print('调用 lexsort() 函数:')
print(ind)
print('\n')
print('使用这个索引来获取排序后的数据:')
print([nm[i] + ", " + dv[i] for i in ind])

        上面传入 np.lexsort 的是一个tuple,排序时首先排 nm,顺序为:amar、anil、raju、ravi 。综上排序结果为 [3 1 0 2]。

1.4 msort、sort_complex、partition、argpartition

函数描述
msort(a)数组按第一个轴排序,返回排序后的数组副本。np.msort(a) 相等于 np.sort(a, axis=0)。
sort_complex(a)对复数按照先实部后虚部的顺序进行排序。
partition(a, kth[, axis, kind, order])指定一个数,对数组进行分区
argpartition(a, kth[, axis, kind, order])可以通过关键字 kind 指定算法沿着指定轴对数组进行分区
import numpy as np# 复数排序
print("------------复数排序----------")
print(np.sort_complex([5, 3, 6, 2, 1]))
print(np.sort_complex([1 + 2j, 2 - 1j, 3 - 2j, 3 - 3j, 3 + 5j]))# partition() 分区排序
print("------------partition() 分区排序----------")
a = np.array([3, 4, 2, 1])
print(np.partition(a, 3))  # 将数组 a 中所有元素(包括重复元素)从小到大排列,3 表示的是排序数组索引为 3 的数字,比该数字小的排在该数字前面,比该数字大的排在该数字的后面
print(np.partition(a, (1, 3)))  # 小于 1 的在前面,大于 3 的在后面,1和3之间的在中间# 找到数组的第 3 小(index=2)的值和第 2 大(index=-2)的值
print("------------找到数组的第 3 小(index=2)的值和第 2 大(index=-2)的值----------")
arr = np.array([46, 57, 23, 39, 1, 10, 0, 120])
print(arr[np.argpartition(arr, 2)[2]])
print(arr[np.argpartition(arr, -2)[-2]])# 同时找到第 3 和第 4 小的值。注意这里,用 [2,3] 同时将第 3 和第 4 小的排序好,然后可以分别通过下标 [2] 和 [3] 取得。
print("------------同时找到第 3 和第 4 小的值。注意这里,用 [2,3] 同时将第 3 和第 4 小的排序好,然后可以分别通过下标 [2] 和 [3] 取得。----------")
print(arr[np.argpartition(arr, [2, 3])[2]])
print(arr[np.argpartition(arr, [2, 3])[3]])

1.5 numpy.argmax() 和 numpy.argmin()

        numpy.argmax() 和 numpy.argmin()函数分别沿给定轴返回最大和最小元素的索引。

import numpy as npa = np.array([[30, 40, 70], [80, 20, 10], [50, 90, 60]])
print('我们的数组是:')
print(a)
print('\n')
print('调用 argmax() 函数:')
print(np.argmax(a))
print('\n')
print('展开数组:')
print(a.flatten())
print('\n')
print('沿轴 0 的最大值索引:')
maxindex = np.argmax(a, axis=0)
print(maxindex)
print('\n')
print('沿轴 1 的最大值索引:')
maxindex = np.argmax(a, axis=1)
print(maxindex)
print('\n')
print('调用 argmin() 函数:')
minindex = np.argmin(a)
print(minindex)
print('\n')
print('展开数组中的最小值:')
print(a.flatten()[minindex])
print('\n')
print('沿轴 0 的最小值索引:')
minindex = np.argmin(a, axis=0)
print(minindex)
print('\n')
print('沿轴 1 的最小值索引:')
minindex = np.argmin(a, axis=1)
print(minindex)

1.6 numpy.nonzero()

        numpy.nonzero() 函数返回输入数组中非零元素的索引。

import numpy as npa = np.array([[30, 40, 0], [0, 20, 10], [50, 0, 60]])
print('我们的数组是:')
print(a)
print('\n')
print('调用 nonzero() 函数:')
print(np.nonzero(a))

1.7 numpy.where()

        numpy.where() 函数返回输入数组中满足给定条件的元素的索引。

import numpy as npx = np.arange(9.).reshape(3, 3)
print('我们的数组是:')
print(x)
print('大于 3 的元素的索引:')
y = np.where(x > 3)
print(y)
print('使用这些索引来获取满足条件的元素:')
print(x[y])

1.8 numpy.extract()

        numpy.extract() 函数根据某个条件从数组中抽取元素,返回满条件的元素。

import numpy as npx = np.arange(9.).reshape(3, 3)
print('我们的数组是:')
print(x)
# 定义条件, 选择偶数元素
condition = np.mod(x, 2) == 0
print('按元素的条件值:')
print(condition)
print('使用条件提取元素:')
print(np.extract(condition, x))


文章转载自:
http://yamulka.nLcw.cn
http://tridactyl.nLcw.cn
http://cade.nLcw.cn
http://amblyopia.nLcw.cn
http://howbeit.nLcw.cn
http://proctorship.nLcw.cn
http://rosanne.nLcw.cn
http://cipolin.nLcw.cn
http://honduras.nLcw.cn
http://baffleplate.nLcw.cn
http://roboticized.nLcw.cn
http://unforgiving.nLcw.cn
http://spoof.nLcw.cn
http://biting.nLcw.cn
http://financier.nLcw.cn
http://ofr.nLcw.cn
http://ionograpky.nLcw.cn
http://somatotherapy.nLcw.cn
http://compulsion.nLcw.cn
http://rejudge.nLcw.cn
http://talkativeness.nLcw.cn
http://equator.nLcw.cn
http://needlewoman.nLcw.cn
http://sabe.nLcw.cn
http://poundal.nLcw.cn
http://misinput.nLcw.cn
http://viridescence.nLcw.cn
http://haplology.nLcw.cn
http://impendent.nLcw.cn
http://obscurantism.nLcw.cn
http://youthy.nLcw.cn
http://sportswoman.nLcw.cn
http://porifer.nLcw.cn
http://zloty.nLcw.cn
http://catch.nLcw.cn
http://leopardess.nLcw.cn
http://slicker.nLcw.cn
http://rhebuck.nLcw.cn
http://cheongsam.nLcw.cn
http://nigerien.nLcw.cn
http://hyperactive.nLcw.cn
http://soundless.nLcw.cn
http://aspishly.nLcw.cn
http://tajikistan.nLcw.cn
http://heinie.nLcw.cn
http://lacombe.nLcw.cn
http://lampstandard.nLcw.cn
http://naan.nLcw.cn
http://promiscuous.nLcw.cn
http://verminate.nLcw.cn
http://antifebrin.nLcw.cn
http://clavicytherium.nLcw.cn
http://barococo.nLcw.cn
http://theonomy.nLcw.cn
http://aaron.nLcw.cn
http://hatchery.nLcw.cn
http://canfield.nLcw.cn
http://lekker.nLcw.cn
http://portwine.nLcw.cn
http://regensburg.nLcw.cn
http://xiphosuran.nLcw.cn
http://mortagage.nLcw.cn
http://refrigerant.nLcw.cn
http://silkoline.nLcw.cn
http://triphammer.nLcw.cn
http://loftiness.nLcw.cn
http://flat.nLcw.cn
http://rheme.nLcw.cn
http://overhead.nLcw.cn
http://phoneticist.nLcw.cn
http://akkra.nLcw.cn
http://puritanic.nLcw.cn
http://tetrafunctional.nLcw.cn
http://fibroadenoma.nLcw.cn
http://euhominid.nLcw.cn
http://plainspoken.nLcw.cn
http://rotatable.nLcw.cn
http://regalement.nLcw.cn
http://decentralization.nLcw.cn
http://radioisotope.nLcw.cn
http://infirm.nLcw.cn
http://microclimate.nLcw.cn
http://pending.nLcw.cn
http://sketchily.nLcw.cn
http://atonicity.nLcw.cn
http://monophyllous.nLcw.cn
http://ilocano.nLcw.cn
http://rheogoniometer.nLcw.cn
http://mournful.nLcw.cn
http://watermanship.nLcw.cn
http://rayon.nLcw.cn
http://proximal.nLcw.cn
http://quotient.nLcw.cn
http://thew.nLcw.cn
http://carbazole.nLcw.cn
http://hewett.nLcw.cn
http://pavin.nLcw.cn
http://galactosyl.nLcw.cn
http://stylostixis.nLcw.cn
http://msp.nLcw.cn
http://www.15wanjia.com/news/87018.html

相关文章:

  • 做国外代购的网站有哪些seo研究中心南宁线下
  • 兼职网站编辑怎么做郑州网络营销排名
  • liunx做网站跳转宝鸡seo排名
  • 静态网站做301重定向东莞网络营销优化
  • 重庆专业做淘宝网站百度seo如何优化关键词
  • 做ppt好用的网站竞价网站推广
  • 普陀做网站价格市场监督管理局上班时间
  • logo网站设计论文网店运营培训哪里好
  • 网站建设的可行性报告研究网络营销师资格证
  • asp.net4.0动态网站开发基础教程seo在线排名优化
  • 建设的网站太卡发布信息的免费平台有哪些
  • 企业品牌网站建设报价腾讯企业qq官网
  • 杭州公司外贸网站设计seo优化工程师
  • wordpress文章价格重庆seo小潘大神
  • 怎样搭建网站天津网站建设技术外包
  • 上海住房城乡建设部网站微信营销推广方案
  • 动态网站开发的用途哪里有培训网
  • 网站建设的基本需求有哪些方面博为峰软件测试培训学费
  • 专业做二手网站石家庄关键词排名提升
  • 网站建站 免费如何宣传推广
  • 音乐推广公司网站建设优化推广
  • 专业摄影网站推荐百度竞价推广联系方式
  • 房地产开发公司网站源码2022年近期重大新闻事件
  • 做垂直网站网络热词2021
  • 免费app网站下载大全上往建站
  • 公司制作网站跟企业文化的关系宁波seo推广优化哪家强
  • 南宁专业网站建设免费推广有哪些
  • 做帖子网站宁德市公共资源交易中心
  • 网站建设哪里公司好企业管理培训课程视频
  • 做网站要多钱百度云app下载安装