Numpy中的1级数组是什么?



考虑以下向量:

import numpy as np
u = np.random.randn(5)
print(u)
[-0.30153275 -1.48236907 -1.09808763 -0.10543421 -1.49627068]

当我们打印它的形状时:

print(u.shape)
(5,)

我被告知这既不是列向量也不是行向量。那么在numpy(m,)中这个形状是什么呢?

# one-dimensional array (rank 1 array)
# array([ 0.202421  ,  1.04496629, -0.28473552,  0.22865349,  0.49918827])
a = np.random.randn(5,) # or b = np.random.randn(5)
# column vector (5 x 1)
# array([[-0.52259951],
#       [-0.2200037 ],
#       [-1.07033914],
#       [ 0.9890279 ],
#       [ 0.38434068]])
c = np.random.randn(5,1)
# row vector (1 x 5)
# array([[ 0.42688689, -0.80472245, -0.86294221,  0.28738552, -0.86776229]])
d = np.random.randn(1,5)

例如(参见文档):

numpy.dot(a, b)
  • 如果a和b都是一维数组,则它们是向量的内积(没有复共轭)。
  • 如果a和b都是二维数组,则为矩阵乘法

最新更新