问题描述
我正在使用Jupyter笔记本.我有一个相当宽的屏幕,但是显示的输出(例如,当我打印numpy
数组时)的格式设置得好像屏幕很窄.
I am using a Jupyter notebook. I have a pretty wide screen, but the displayed output (say, when I print a numpy
array) is formatted as if the screen was narrow.
我找到了一种增加细胞宽度的方法,
I found a way of increasing the width of the cells, with
from IPython.core.display import HTML
HTML("<style>.container { width:95% !important; }</style>")
但这似乎只影响输入,而不影响输出(请参见屏幕截图):
but this seems to influence the input only, not the output (see screenshots):
我尝试在numpy.set_printoptions
中设置linewidth
选项,我尝试设置numpy.core.arrayprint._line_width
,什么都没有...
I've tried setting the linewidth
option in numpy.set_printoptions
, I've tried setting numpy.core.arrayprint._line_width
, nothing...
使用matplotlib可以使用命令plt.rcParams['figure.figsize']=[X,Y]
设置绘图的宽度(使用魔术%matplotlib inline
在笔记本中绘图).事实证明,我可以增加X
来使图一直水平地填充输出单元格.这意味着(我认为)原来的问题是numpy
问题.
Using matplotlib I can set the width of plots (that I plot in the notebook with the magic %matplotlib inline
) with the command plt.rcParams['figure.figsize']=[X,Y]
. It turns out that I can increase X
to have plots fill the output cell horizontally all the way. This means (I think) that the original problem it's a numpy
thing.
推荐答案
这已经一岁了,但也许答案会对其他人有所帮助.
This is a year old now but maybe the answer will help someone else.
numpy-arrays的显示方式取决于许多因素.使用此代码,您可以显示更多项目并使用屏幕的整个宽度:
The way numpy-arrays are displayed depends on a number of things.With this code, you can show more items and use the full width of your screen:
这是默认设置
import numpy as np
np.set_printoptions(edgeitems=3)
np.core.arrayprint._line_width = 80
>>> array([[[0, 0, 0, ..., 0, 0, 0],
>>> [0, 0, 0, ..., 0, 0, 0],
>>> [0, 0, 0, ..., 0, 0, 0],
>>> ...,
使用以下代码,您可以增加每个数组边缘(开始和结束)以及行宽处显示的项目:
With the following code you increase the items shown at the edge of each array (start and end) as well as the line width:
import numpy as np
np.set_printoptions(edgeitems=10)
np.core.arrayprint._line_width = 180
>>> array([[[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
>>> [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
>>> [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
这篇关于如何在numpy中设置最大输出宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!