gpt4 book ai didi

python - numpy 数组的 set_printoptions 不适用于 numpy ndarray?

转载 作者:太空宇宙 更新时间:2023-11-04 02:21:34 24 4
gpt4 key购买 nike

我正在尝试使用问题 How to pretty-printing a numpy.array without scientific notation and with given precision? 的答案中的 set_printoptions

但是我得到这个错误:

Traceback (most recent call last):
File "neural_network.py", line 57, in <module>
output.set_printoptions(precision=3)
AttributeError: 'numpy.ndarray' object has no attribute 'set_printoptions'

显然,并不是所有的 numpy 数组都是一样的,适用于常规 numpy.array 的方法不适用于 numpy.ndarray.

我如何格式化 numpy.ndarray 以进行打印,例如删除科学记数法?

更新

更改对 numpy.set_printoptions() 的调用可消除错误,但对 ndarray 内容的打印格式没有影响。

最佳答案

试试 numpy.array2string,它以 ndarray 作为输入,你可以设置精度。

在下面的文档链接中向下滚动以获取示例。

https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.array2string.html

关于python - numpy 数组的 set_printoptions 不适用于 numpy ndarray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51485042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com