numpy合并排序数组到一个新的数组? [英] numpy merge sorted array to an new array?

查看:69
本文介绍了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.

这篇关于numpy合并排序数组到一个新的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆