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

Ale*_*x R 5 python arrays numpy

我正在尝试使用set_printoptions问题的答案如何在没有科学记数法和给定精度的情况下漂亮地打印 numpy.array?

但我收到这个错误:

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'
Run Code Online (Sandbox Code Playgroud)

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

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

更新

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

Pav*_*aka 5

尝试numpy.array2string将其ndarray作为输入,您可以设置精度。

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

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

  • 虽然很高兴知道为什么 numpy.set_printoptions() 不起作用,但这个答案确实解决了我以 precision=3 打印数组的实际问题 (2认同)