欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

对python numpy.array插入一行或一列的方法详解

程序员文章站 2023-10-17 20:37:23
如下所示: import numpy as np a = np.array([[1,2,3],[4,5,6],[7,8,9]]) b = np.array([...

如下所示:

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

以上这篇对python numpy.array插入一行或一列的方法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。