首页 > 解决方案 > 在python中对不同大小的数组进行排序

问题描述

我有 2 个 np.array 对象

non_direct_start = [5 100]

direct_start = [1 9 105]

我想或他们按升序排列

idx_start =

     [1     5     9   100   105]

我尝试使用 np.sort 对这些进行排序,但它显示错误

idx_start = np.sort((non_direct_start, direct_start))

ValueError: operands could not be broadcast together with shapes (3,) (2,)

有没有可用的功能来做到这一点?还是我必须走循环方式?

标签: pythonnumpy

解决方案


用于np.concatenate将它们加入一个数组,然后np.sort

np.sort(np.concatenate((non_direct_start, direct_start)))

输出:

array([  1,   5,   9, 100, 105])

推荐阅读