简体   繁体   English

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

[英]set_printoptions for numpy array doesn't work for numpy ndarray?

I'm trying to use set_printoptions from the answer to the question How to pretty-printing a numpy.array without scientific notation and with given precision? 我正在尝试从问题的答案中使用set_printoptions如何在没有科学符号和给定精度的情况下漂亮地打印numpy.array?

But I get this error: 但是我得到这个错误:

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'

Apparently, not all numpy arrays are created equal, and what works for a regular numpy.array doesn't work for a numpy.ndarray . 显然,并非所有的numpy数组都被创建为相等,并且对于常规numpy.array不适用于numpy.ndarray

How can I format a numpy.ndarray for priting such as to remove scientific notation? 我该如何格式化numpy.ndarray进行表决,例如删除科学计数法?

UPDATE UPDATE

Changing the call to numpy.set_printoptions() removes the error, but has no effect on the print format of the ndarray contents. 将调用更改为numpy.set_printoptions()可以消除该错误,但对ndarray内容的打印格式没有影响。

Try numpy.array2string which takes ndarray as input and you can set precision. 尝试numpy.array2string ndarray作为输入的ndarray ,您可以设置精度。

Scroll down in below documentation link for examples. 在下面的文档链接中向下滚动以获取示例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM