import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
b = np.ones(3)
c = np.array([[1,2,3,1],[4,5,6,1],[7,8,9,1]])
PRint(a)
print(b)
print(c)

[[1 2 3]
 [4 5 6]
 [7 8 9]]
[ 1.  1.  1.]
[[1 2 3 1]
 [4 5 6 1]
[7 8 9 1]]

常用方法

使用np.c[]和np.r[]分别添加行和列

np.c_[a,b]




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




np.c_[a,a]




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




np.c_[b,a]




array([[ 1.,  1.,  2.,  3.],
       [ 1.,  4.,  5.,  6.],