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))”