长NumPy数组无法完整打印?

发布于 2024-10-09 06:50:35 字数 212 浏览 0 评论 0原文

我试图打印两个 1001x1 数组的完整内容,但 Python 只给我截断的输出,如下所示:

array([[5,45],
       [1,23],
       ......,
       [1,24],
       [2,31]])  

而不是完整的数组。

谁能告诉我如何获得完整的 1001x1 数组的解决方案?

I'm trying to print the complete contents of two 1001x1 arrays, but Python only gives me truncated output something like this:

array([[5,45],
       [1,23],
       ......,
       [1,24],
       [2,31]])  

instead of the complete array.

Can anyone give me solution of how to get the complete 1001x1 array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独留℉清风醉 2024-10-16 06:50:35

请参阅打印数组部分NumPy 教程:

如果数组太大而无法打印,NumPy 会自动跳过数组的中心部分,只打印角点:

<前><代码>>>>打印(np.arange(10000))
[ 0 1 2 ..., 9997 9998 9999]

...

要禁用此行为并强制 NumPy 打印整个数组,您可以使用 set_printoptions 更改打印选项。

<前><代码>>>> np.set_printoptions(阈值=nan)

np.set_printoptions 函数是 NumPy 库的一部分。

See the section Printing Arrays in the NumPy tutorial:

If an array is too large to be printed, NumPy automatically skips the central part of the array and only prints the corners:

>>> print(np.arange(10000))
[   0    1    2 ..., 9997 9998 9999]

...

To disable this behaviour and force NumPy to print the entire array, you can change the printing options using set_printoptions.

>>> np.set_printoptions(threshold=nan)

The np.set_printoptions function is part of the NumPy library.

帥小哥 2024-10-16 06:50:35

我猜测您尝试了一个简单的语句,例如:

print myarray

... 而不是更明确的语句,例如:

for each_item in myarray:
    print each_item

... 甚至:

print ', '.join([str(x) for x in myarray])

您看到省略的输出的原因大概是因为 numpy 在其 array 类中实现一个 _str_ 方法,该方法尝试给出“合理”的默认值
数组的字符串表示形式。据推测,他们假设简单的 print 语句将主要用于调试、日志记录或类似目的,并且将完成结果报告或将结果编组到其他进程或存储对数据使用更明确的迭代(正如我在这里所示)。

I'm going to guess that you tried a simple statement like:

print myarray

... rather than something more explicit like:

for each_item in myarray:
    print each_item

... or even:

print ', '.join([str(x) for x in myarray])

The reason you're seeing elided output is, presumably, because numpy implements a _str_ method in its array class which tries to give a "reaasonable" default
string representation of the array. They are, presumably, assuming that simple print statements will be used primarily for debugging, logging, or similar purposes and that reporting of results, or marshaling of results to other processes or storage, is going to be done using more explicit iterations over the data (as I've shown here).

月亮坠入山谷 2024-10-16 06:50:35

以下对我有用:

np.set_printoptions(threshold=sys.maxsize)

The following worked for me:

np.set_printoptions(threshold=sys.maxsize)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文