我有一个1d数组,我想将其打印为一列。

r1 = np.array([54,14,-11,2])
print r1

给我这个:
 [ 54  14 -11   2]


 print r1.shape

给我这个:
(4L,)

有什么我可以插入np.reshape()以便
print r1.shape

给我这个吗?
(,4L)

打印输出看起来像
 54
 14
-11
 2

最佳答案

这将起作用:

import numpy as np

r1 = np.array([54,14,-11,2])

r1[:, None]

# array([[ 54],
#        [ 14],
#        [-11],
#        [  2]])

关于python - numpy将一维数组打印为列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48724936/

10-13 07:06