长NumPy数组无法完整打印?
我试图打印两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅打印数组部分NumPy 教程:
np.set_printoptions
函数是 NumPy 库的一部分。See the section Printing Arrays in the NumPy tutorial:
The
np.set_printoptions
function is part of the NumPy library.我猜测您尝试了一个简单的语句,例如:
... 而不是更明确的语句,例如:
... 甚至:
您看到省略的输出的原因大概是因为
numpy
在其array
类中实现一个_str_
方法,该方法尝试给出“合理”的默认值数组的字符串表示形式。据推测,他们假设简单的
print
语句将主要用于调试、日志记录或类似目的,并且将完成结果报告或将结果编组到其他进程或存储对数据使用更明确的迭代(正如我在这里所示)。I'm going to guess that you tried a simple statement like:
... rather than something more explicit like:
... or even:
The reason you're seeing elided output is, presumably, because
numpy
implements a_str_
method in itsarray
class which tries to give a "reaasonable" defaultstring 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).以下对我有用:
The following worked for me: