版本:
numpy=1.19.3
python=3.6
代碼:
import numpy as np
a = np.array([[12],[26],[40],[66]])
print(a.shape)
result:
(4, 1)
將(4,1)轉為(4,)
a_post_1 = np.squeeze(a)
print(a_post_1.shape)
result:
(4,)
代碼:
import numpy as np
b = np.array([12,26,40,66])
print(b.shape)
result:
(4,)
將(4,)轉為 (4,1)
b_post_1 = b.reshape(-1,1)
print(b_post_1.shape)
或者
b_post_2 = np.reshape(b,(-1,1))
print(b_post_2.shape)
result:
(4, 1)
(4, 1)
參考:https://blog.csdn.net/zkp_987/article/details/119989767