【问题标题】:How to print the full NumPy array without wrapping (in Jupyter Notebook)如何在不换行的情况下打印完整的 NumPy 数组(在 Jupyter Notebook 中)
【发布时间】:2019-08-23 06:40:21
【问题描述】:

这个问题和这个问题不同:How to print the full NumPy array, without truncation?

在那个问题中,用户想知道如何在没有截断的情况下打印完整的数组。我可以打印没有截断的数组就好了。 我的问题是只使用了屏幕宽度的一小部分。在尝试检查大型邻接矩阵时,如果行不必要地换行,则无法检查它们。

我在这里问这个问题是因为我总是需要几个小时才能找到解决方案,我想从上面的答案中消除歧义。

例如:

import networkx as nx
import numpy as np
np.set_printoptions(threshold=np.inf)
graph = nx.gnm_random_graph(20, 20, 1)
nx.to_numpy_matrix(graph)

此输出显示为:

【问题讨论】:

  • np.set_printoptions(linewidth=100) 或其他
  • 写你自己的好老print_as_you_like_to_see_it()函数也许?
  • 在这里回答了类似的问题:stackoverflow.com/a/59058418/3857460.

标签: python arrays numpy jupyter-notebook


【解决方案1】:

只是将 NaN 的评论作为答案发布:

使用np.set_printoptions(linewidth=n),其中n 与每行的字符数(不是数组元素)有关。所以在你的情况下n=100 应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 2022-08-19
    • 1970-01-01
    • 2021-08-21
    • 2019-02-27
    相关资源
    最近更新 更多