python - 如何在 numpy 中设置最大输出宽度?

标签 python css numpy ipython

我正在使用 Jupyter 笔记本。我有一个相当宽的屏幕,但显示的输出(例如,当我打印一个 numpy 数组时)的格式就像屏幕很窄一样。

我找到了一种增加单元格宽度的方法,用

from IPython.core.display import HTML
HTML("<style>.container { width:95% !important; }</style>")

但这似乎只影响输入,不影响输出(见截图):

short input longer input

我试过在 numpy.set_printoptions 中设置 linewidth 选项,我试过设置 numpy.core.arrayprint._line_width,没什么...

编辑:使用 matplotlib 我可以使用命令 plt.rcParams['figure.figsize' ]=[X,Y]。事实证明,我可以增加 X 以使绘图一直水平填充输出单元格。这意味着(我认为)原始问题是 numpy 问题。

最佳答案

我找到了 this answer有助于创建我自己的:

import numpy as np
np.set_printoptions(edgeitems=30, linewidth=100000, 
    formatter=dict(float=lambda x: "%.3g" % x))

荒谬的线宽意味着只有 edgeitems 并且窗口的宽度将决定何时发生换行/换行。

enter image description here

如果我稍微缩小窗口,它看起来像这样,所以你可能仍然需要使用 edgeitems 或格式化:

enter image description here

Here are the docs对于 set_printoptions,以下是相关的:

  • edgeitems :每个维度开始和结束时汇总的数组项数(默认为 3)。

  • linewidth :为插入换行符而设置的每行字符数(默认为 75)。

关于python - 如何在 numpy 中设置最大输出宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37149933/

相关文章:

css - 建议在 CSS 中键入颜色的名称而不是其十六进制值?

html - 下拉菜单问题

html - : white lines over images in internet explorer如何解决

python - 当数据文件只有一行时,numpy genfromtxt collapse recarray

python - 在 python 中将整数数组转换为颜色字符串或颜色值的快速方法

python - Django FileField 存储选项

python - Python 中的多处理池 - 仅使用单个 CPU

python - 如何在 jupyter notebook 中触发保存命令?

python - 在 Python 数组或 numpy 数组中过滤掉 nan 或 invalid 的更简单方法?

python 将重复项合并到一个列表中并合并结果