1.问题描述
在使用numpy的时候,我们经常在debug的时候将numpy数组打印下来,但是有的时候数组里面都是小数,数组又比较大,打印下来的时候非常不适合观察。这里主要讲一下如何让numpy打印的结果更加简洁
2.问题解决
这里需要使用numpy的set_printoptions函数,对应numpy源码如下所示:
def set_printoptions(precision=None, threshold=None, edgeitems=None,
linewidth=None, suppress=None,
nanstr=None, infstr=None,
formatter=None):
"""
Set printing options.
These options determine the way floating point numbers, arrays and
other NumPy objects are displayed.
Parameters
----------
precision : int, optional
Number of digits of precision for floating point output (default 8).
threshold : int, optional
Total number of array elements which trigger summarization
rather than full repr (