首先要说明的是,无论是行向量还是列向量,shape都是二维的,不过其中有一维是1,一个list既不是行向量也不是列向量。
行向量
import numpy as np
b=np.array([1,2,3]).reshape((1,-1))
print(b,b.shape)
'''
结果:
(array([[1, 2, 3]]), (1, 3))
'''
# 或者下面这种方法
b=np.array([[1,2,3]]) #两层'[]'
print(b,b.shape)
'''
结果
(array([[1, 2, 3]]), (1, 3))
'''
列向量
import numpy as np
a=np.array([1,2,3]).reshape((-1,1))
print(a,a.shape)
'''
结果:
(array([[1],
[2],
[3]]), (3, 1))
'''
a=np.array([[1,2,3]]).T
print(a,a.shape)
'''
(array([[1],
[2],
[3]]), (3, 1))
'''