版本:
numpy=1.19.3
python=3.6
一、 (n,1) 转 (n,)
代码:
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,)
二、 (n,) 转 (n,1)
代码:
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)