当我打印一个numpy数组时,我得到一个截断的表示,但我想要完整的数组。
有什么方法可以做到这一点吗?
例子:
>>> numpy.arange(10000)
array([ 0, 1, 2, ..., 9997, 9998, 9999])
>>> numpy.arange(10000).reshape(250,40)
array([[ 0, 1, 2, ..., 37, 38, 39],
[ 40, 41, 42, ..., 77, 78, 79],
[ 80, 81, 82, ..., 117, 118, 119],
...,
[9880, 9881, 9882, ..., 9917, 9918, 9919],
[9920, 9921, 9922, ..., 9957, 9958, 9959],
[9960, 9961, 9962, ..., 9997, 9998, 9999]])
使用[numpy.set_printoptions
](http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html)。
import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)
这听起来像是你在使用numpy。
如果是这样的话,你可以添加。
import numpy as np
np.set_printoptions(threshold=np.nan)
这将使角部打印功能失效。 更多信息,请看这个NumPy教程。
这里有一个一次性的方法,如果你不想改变你的默认设置,这很有用。
def fullprint(*args, **kwargs):
from pprint import pprint
import numpy
opt = numpy.get_printoptions()
numpy.set_printoptions(threshold='nan')
pprint(*args, **kwargs)
numpy.set_printoptions(**opt)