np.set_printoptions
numpy.set_printoptions(precision=None,
threshold=None,
edgeitems=None,
linewidth=None,
suppress=None,
nanstr=None,
infstr=None,
formatter=None
)[source]
参数:
precision:int,可选
浮点数输出的精度位数(默认为8)。
阈值:int,可选
触发汇总而不是完全repr的数组元素的总数(默认为1000)。
edgeitems:int,可选
在每个维度的开始和结束处的摘要中的数组项数(默认值为3)。
linewidth:int,可选
用于插入换行符的每行字符数(默认为75)。
suppress:bool,可选
是否使用科学计数法抑制小浮点值的打印(默认值为False)。
nanstr:str,可选
浮点数的字符串表示不是数字(默认为nan)。
infstr:str,可选
浮点无穷大的字符串表示形式(默认inf)。
格式化程序:可调用的dict,可选
如果不是无,键应该指示相应格式化功能应用的类型。Callables应该返回一个字符串。未指定的类型(通过其相应的键)由默认格式化程序处理。可以设置格式化程序的单个类型有:
- 'bool'
- 'int'
- 'timedelta' : a `numpy.timedelta64`
- 'datetime' : a `numpy.datetime64`
- 'float'
- 'longfloat' : 128-bit floats
- 'complexfloat'
- 'longcomplexfloat' : composed of two 128-bit floats
- 'numpy_str' : types `numpy.string_` and `numpy.unicode_`
- 'str' : all other strings
可用于一次设置一组类型的其他键有:
- 'all' : sets all types
- 'int_kind' : sets 'int'
- 'float_kind' : sets 'float' and 'longfloat'
- 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
- 'str_kind' : sets 'str' and 'numpystr'
浮点精度可设置:
>>> np.set_printoptions(precision=4)
>>> print(np.array([1.123456789]))
[ 1.1235]
长数组可概括为:
>>> np.set_printoptions(threshold=5)
>>> print(np.arange(10))
[0 1 2 ..., 7 8 9]
NumPy v1.11 ManualNumPy参考例程输入和输出:http://doc.codingdict.com/NumPy_v111/reference/generated/numpy.set_printoptions.html#numpy.set_printoptions