python - 在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,)
有没有可用的功能来做到这一点?还是我必须走循环方式?
解决方案
用于np.concatenate
将它们加入一个数组,然后np.sort
:
np.sort(np.concatenate((non_direct_start, direct_start)))
输出:
array([ 1, 5, 9, 100, 105])
推荐阅读
- android - ListView 未显示在导航菜单中
- heroku - 有什么解决办法吗?我收到错误消息:这里什么都没有。当我在heroku中添加自定义域时
- flutter - 重置 Provider 中的字段或变量
- c++ - 使用位掩码和指针从 int 中保存一个字节
- javascript - 为什么异步函数返回未定义?
- android - 将华为身份验证添加到使用 Firebase 身份验证的现有应用程序
- c++ - 哪个 DLL 导出 NtGdiBeginGdiRendering 函数以及如何导出?
- json - Flipper的(调试平台)日志数据默认折叠
- java - 如何生成动态按钮取决于 Firebase 中的数据量
- vb.net - 为什么我的 VB 代码会收到此特定错误消息?