Shi*_*tsu 6 python printing arrays numpy
当一行中有足够的空间容纳所有内容时,它会在 5 列之后自动换行。例如:
print array
==========================restart=========================================
([32235, 2323424, 2342342
3525324, 234234])
([234234, 23423, 543535,
76572, 23424])
Run Code Online (Sandbox Code Playgroud)
使用 python Idle,我尝试更改初始窗口大小首选项。重启栏一直延伸,但不是 numpy 数组输出。
搜索后似乎也找不到答案。我病了,非常感谢任何帮助。谢谢!
Ata*_*ias 18
您的问题的实际答案(不需要牺牲精度)如下:
import numpy as np
large_width = 400
np.set_printoptions(linewidth=large_width)
Run Code Online (Sandbox Code Playgroud)
小智 4
尝试使用np.vectorize:
printer = np.vectorize(lambda x:'{0:5}'.format(x,))
print printer(b).astype(object)
Run Code Online (Sandbox Code Playgroud)
或者尝试使用np.set_printoptions:
正如 IDLE 中所示:
>>> import numpy as np
>>> x=np.random.random(10)
>>> x
array([ 0.72239823, 0.69938461, 0.85466846, 0.03294278, 0.06698482,
0.04137562, 0.4223521 , 0.81317235, 0.62221494, 0.6205595 ])
>>> np.set_printoptions(precision=3)
>>> print(x)
[ 0.722 0.699 0.855 0.033 0.067 0.041 0.422 0.813 0.622 0.621]
Run Code Online (Sandbox Code Playgroud)