np.c_ 用於連接兩個矩陣
np.c 中的c 是 column(列)的縮寫,就是按列疊加兩個矩陣,就是把兩個矩陣左右組合,要求行數相等。
# -*- coding: utf-8 -*
import numpy as np
x_1 = np.array([1, 2, 3, 4, 5, 6]).reshape(2, 3)
x_2 = np.array([3, 2, 1, 8, 9, 6]).reshape(2, 3)
x_new = np.c_[x_1,x_2]
print("x_1 = \n",x_1)
print("x_2 = \n",x_2)
print("x_new = \n",x_new)
結果輸出如下:
x_1 =
[[1 2 3]
[4 5 6]]
x_2 =
[[3 2 1]
[8 9 6]]
x_new =
[[1 2 3 3 2 1]
[4 5 6 8 9 6]]