📌  相关文章
📜  在特定位置向 numpy 数组插入新行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:54.877000             🧑  作者: Mango

代码示例1
>>> import numpy as np
>>> a = np.zeros((2, 2))
>>> a
array([[ 0.,  0.],
       [ 0.,  0.]])
# In the following line 1 is the index before which to insert, 0 is the axis.
>>> np.insert(a, 1, np.array((1, 1)), 0)  
array([[ 0.,  0.],
       [ 1.,  1.],
       [ 0.,  0.]])
>>> np.insert(a, 1, np.array((1, 1)), 1)
array([[ 0.,  1.,  0.],
       [ 0.,  1.,  0.]])