簡體   English   中英

在 python 中對不同大小的 arrays 進行排序

[英]Sort different sized arrays in 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,)

是否有任何 function 可用於執行此操作? 或者我必須 go 循環方式?

使用np.concatenate將它們加入一個數組,然后np.sort

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

Output:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM