最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

numpy合并排序数组到一个新的数组?

SEO心得admin41浏览0评论
本文介绍了numpy合并排序数组到一个新的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有什么方法可以使用numpy函数在mergesort中进行合并吗?

Is there any way we can do something like merge in mergesort using numpy function?

一些功能,例如合并:

a = np.array([1,3,5]) b = np.array([2,4,6]) c = merge(a, b) # c == np.array([1,2,3,4,5,6])

我希望借助numpy能够获得大数据的高性能

I wish I could get high performance for large data thanks to numpy

推荐答案

您可以使用

from numpy import concatenate, sort c = concatenate((a,b)) c.sort(kind='mergesort')

除非您编写自己的排序功能作为python扩展名,否则恐怕您无法做得更好,如cython.

I am afraid you can't do better than this, unless you write your own sorting function as a python extension, à la cython.

有关类似问题,请参见此问题,但仅在其中保留唯一值合并的数组.那里的基准和评论也很有见地.

See this question for a similar problem, but keeping only the unique values in the merged array. The benchmarks and comments there are insightful as well.

发布评论

评论列表(0)

  1. 暂无评论