Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为numpy数组设置打印选项';你不为numpy Ndaray工作吗?_Python_Arrays_Numpy - Fatal编程技术网

Python 为numpy数组设置打印选项';你不为numpy Ndaray工作吗?

Python 为numpy数组设置打印选项';你不为numpy Ndaray工作吗?,python,arrays,numpy,Python,Arrays,Numpy,我试图从问题的答案中使用set\u 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' 回

我试图从问题的答案中使用
set\u 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'
回溯(最近一次呼叫最后一次):
文件“neural_network.py”,第57行,在
输出。设置打印选项(精度=3)
AttributeError:'numpy.ndarray'对象没有属性'set\u printoptions'
显然,并不是所有的
numpy
数组都被创建为相等的,对于常规
numpy.array
有效的数组并不适用于
numpy.ndarray

我如何为priting设置
numpy.ndarray
格式,例如删除科学符号

更新


将调用更改为
numpy.set_printoptions()
会删除错误,但不会影响数据数组内容的打印格式。

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

在下面的文档链接中向下滚动查看示例


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

在下面的文档链接中向下滚动查看示例


使用suppress=True可以解决以下问题:

np.set_printoptions(precision = 2, suppress= True)

使用suppress=True可以解决以下问题:

np.set_printoptions(precision = 2, suppress= True)

设置打印选项
是模块级功能。它不是
ndarray
的方法。我们随便称之为
numpy
数组实际上是类
np.ndarray
的对象
np
numpy
指我们导入的模块。没有“常规nupy.array”这样的东西。也许我的问题应该重新措辞:为了使用
ndarray
,应该如何调用模块级函数
set\u printoptions
?链接中的公认答案显示了如何使用
np.set\u printoptions
。其他答案显示了如何在
上下文中使用它。该链接还有一个使用
array2string
的答案。如果您想让我们诊断为什么
numpy.set\u printoptions
对您不起作用,您必须显示更多代码。
set\u printoptions
是模块级功能。它不是
ndarray
的方法。我们随便称之为
numpy
数组实际上是类
np.ndarray
的对象
np
numpy
指我们导入的模块。没有“常规nupy.array”这样的东西。也许我的问题应该重新措辞:为了使用
ndarray
,应该如何调用模块级函数
set\u printoptions
?链接中的公认答案显示了如何使用
np.set\u printoptions
。其他答案显示了如何在
上下文中使用它。该链接还有一个使用
array2string
的答案。如果您想让我们诊断为什么
numpy.set\u printoptions
对您不起作用,您必须显示更多的代码。虽然很高兴知道为什么numpy.set\u printoptions()不起作用,但这个答案确实解决了我打印精度为3的数组的实际问题,可能是调用风格有点不同。。。。在这里,我在下面的存储库中找到了一个查找“np.set_printoptions”的示例,您可以尝试与链接(上面的注释)中所述相同的方法…首先,通过设置精度并调用print函数,指定您的数组是np.array的一种类型“print(np.array(output)),同时很高兴知道为什么numpy.set_printoptions()不起作用,这个答案确实解决了我打印精度为3的数组的实际问题,可能是调用方式有点不同。。。。在这里,我在下面的存储库中找到了一个查找“np.set_printoptions”的示例,您可以尝试与链接(上面的注释)中所述相同的方法…首先,通过设置精度并调用print函数,指定您的数组是np.array的一种类型“print(np.array(output))”