您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何打印小数点后3位的numpy数组?

如何打印小数点后3位的numpy数组?

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.unicode_`
    - 'str' : all other strings

Other 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'
其他 2022/1/1 18:29:26 有467人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶