我有兩個 numpy 2d 陣列,我想將它們堆疊起來,但要放在我要放置它們的特定行中。
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 中執行此操作的最快方法是什么?
uj5u.com熱心網友回復:
對于您的特定示例:
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]])
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/347555.html
標籤:Python 数组 麻木的 numpy-ndarray
