np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})这会将numpy设置为使用此lambda函数来格式化其打印出的每个浮点数。
您可以定义其他格式的类型(来自函数的文档字符串)
- '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.unipre_` - 'str' : all other stringsOther keys that can be used to set a group of types at once are:: - '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'


![如何打印小数点后3位的numpy数组?[重复] 如何打印小数点后3位的numpy数组?[重复]](http://www.mshxw.com/aiimages/31/668285.png)
