栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何打印小数点后3位的numpy数组?[重复]

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何打印小数点后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.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'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668285.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号