我在python中使用numpy数组,我正在尝试更好地将它们可视化以查看我正在使用的内容。当数组换行到下一行时有没有办法改变? 例如,在终端窗口中,我有足够的列在一行上显示0-49,但当我转换为数组数据类型时它会自动换行。
>>> tmp.shape
(2, 50)
>>> print tmp
[[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49]
[50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99]]
>>>
答案 0 :(得分:12)
http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html
默认情况下,Numpy在显示数组时仅打印75个字符。您可以使用numpy.set_printoptions()
更改此设置例如。我将我的终端设置为显示132x43并得到了这个:
>>> import numpy as np
>>> np.set_printoptions(linewidth=132)
>>> a = np.arange(100).reshape(2,50)
>>> a
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
[50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]])