# 给矩阵m_arr同时新增一行和一列元素
m_list = [[1, 2, 3], [3, 4, 5]]
m_arr = np.array(m_list) # 转为数组
news_row = np.full((1, 3), -1)
print("news_row", news_row)
n1 = np.append(m_arr, news_row, axis=0) # 添加整行元素
print("n1", n1)
news_col = np.full((n1.shape[0], 1), -1)
print("news_col", news_col)
n2 = np.append(n1, news_col, axis=1) # 添加整列
print(n1)
print(n2)
news_row [[-1 -1 -1]]
n1 [[ 1 2 3]
[ 3 4 5]
[-1 -1 -1]]
news_col [[-1]
[-1]
[-1]]
[[ 1 2 3]
[ 3 4 5]
[-1 -1 -1]]
[[ 1 2 3 -1]
[ 3 4 5 -1]
[-1 -1 -1 -1]]