Prohibit automatic linebreaks in Pycharm Output when using large Matrices(使用大型矩阵时禁止 Pycharm 输出中的自动换行符)
问题描述
我在 Windows 上的 PyCharm 中工作.在我目前正在处理的项目中,我有大"矩阵,但是当我输出它们时,Pycharm 会自动添加换行符,以便一行占用两行而不是一行:
I'm working in PyCharm on Windows. In the project I'm currently working on I have "large" matrices, but when i output them Pycharm automatically adds linebreaks so that one row occupys two lines instead of just one:
[[ 3. -1.73205081 0. 0. 0. 0. 0.
0. 0. 0. ]
[-1.73205081 1. -1. -2. 0. 0. 0.
0. 0. 0. ]
[ 0. -1. 1. 0. -1.41421356 0. 0.
0. 0. 0. ]
[ 0. -2. 0. 1. -1.41421356 0.
-1.73205081 0. 0. 0. ]
[ 0. 0. -1.41421356 -1.41421356 0. -1.41421356
0. -1.41421356 0. 0. ]
[ 0. 0. 0. 0. -1.41421356 0. 0.
0. -1. 0. ]
[ 0. 0. 0. -1.73205081 0. 0. 3.
-1.73205081 0. 0. ]
[ 0. 0. 0. 0. -1.41421356 0.
-1.73205081 1. -2. 0. ]
[ 0. 0. 0. 0. 0. -1. 0.
-2. 0. -1.73205081]
[ 0. 0. 0. 0. 0. 0. 0.
0. -1.73205081 0. ]]
这让我的结果很难被解读和比较.窗口足够大,可以显示所有内容,但仍会破坏行.有什么设置可以防止这种情况发生吗?
It make my results very hard to reed and to compare. The window is big enough so that everything should be displayed but it still breaks the rows. Is there any setting to prevent this?
提前致谢!
推荐答案
PyCharm 默认控制台宽度设置为 80 个字符.除非您在选项中设置 soft wrap
,否则将打印行而不换行:文件->设置->编辑器->一般->控制台->在控制台中使用软包装
.
PyCharm default console width is set to 80 characters.
Lines are printed without wrapping unless you set soft wrap
in options:
File -> Settings -> Editor -> General -> Console -> Use soft wraps in console
.
但是,这两个选项都使读取大矩阵变得困难.您可以通过几种方式解决此问题.
However both options make reading big matrices hard. You can fix this in few ways.
使用此测试代码:
import random
m = [[random.random() for a in range(10)] for b in range(10)]
print(m)
您可以尝试以下方法之一:
You can try one of these:
使用pprint
模块,并覆盖行width:
import pprint
pprint.pprint(m, width=300)
麻木
对于 numpy 版本 1.13 及更低版本:
Numpy
For numpy version 1.13 and lower:
如果你使用 numpy
模块,配置 arrayprint 选项:
If you use numpy
module, configure arrayprint option:
import numpy
numpy.core.arrayprint._line_width = 300
print(numpy.matrix(m))
numpy 版本 1.14 及以上版本(感谢@Alex Johnson):
For numpy version 1.14 and above (thanks to @Alex Johnson):
import numpy
numpy.set_printoptions(linewidth=300)
print(numpy.matrix(m))
熊猫
如果你使用 pandas
模块,配置 display.width 选项:
Pandas
If you use pandas
module, configure display.width option:
import pandas
pandas.set_option('display.width', 300)
print(pandas.DataFrame(m))
这篇关于使用大型矩阵时禁止 Pycharm 输出中的自动换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用大型矩阵时禁止 Pycharm 输出中的自动换行符


基础教程推荐
- 修改列表中的数据帧不起作用 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01