在特定行上堆叠二维数组

Stack 2d array on specific row

我有两个 numpy 二维数组,我想将它们堆叠起来,但要将它们堆叠到我要放置它们的特定行中。

a = ([[4, 2],
      [7, 3],
      [1, 8]])

b = ([[10, 6],   (put in 3rd row)
      [9, 5]]) (put in 5th row)

Expected output = ([[4, 2],
                    [7, 3],
                    [10, 6],
                    [1, 8],
                    [9, 5]])

在 python 中最快的方法是什么?

对于您的特定示例:

import numpy as np
a = np.array([[1, 2],[3, 4],[7, 8]])
b = np.array([[5, 6],[9, 10]])
np.insert(a,[2,3],b,axis=0)

输出:

array([[ 1,  2],
   [ 3,  4],
   [ 5,  6],
   [ 7,  8],
   [ 9, 10]])