【问题标题】:How to force Python not to use "..." in long strings? [duplicate]如何强制 Python 不在长字符串中使用“...”? [复制]
【发布时间】:2021-06-27 21:43:49
【问题描述】:

我使用了以下程序:

def show(self):
        output = str(self.inodes) + " " + str(self.hnodes) + " " + str(self.onodes) + " " + str(self.lr) + " " + str(self.wih) + " " + str(self.who)
        
        return output

以字符串形式获取神经网络的统计信息,然后我想通过以下方式保存:

networkSave = n.show()
datei = open("FILEPATH/FILENAME.txt", mode='w')
datei.write(networkSave)
datei.close()

在 txt 文件中。到目前为止,该代码运行良好。问题是,虽然在我的设计中,数组“self.wih”有超过 70.000 个条目,我在上述 txt 文件中得到了这些点,其中数组仅被缩写描述:

[[ 0.02742568  0.07564016  0.01795626 ...  0.01656147 -0.07529069
   0.00203228]
 [ 0.01877599 -0.07540431 -0.02055005 ...  0.03289611 -0.01307233
  -0.01261936]
 [-0.0029786  -0.05353505 -0.04538922 ... -0.004011   -0.03398194
  -0.0058061 ]

有人知道如何强制 python 将整个数组作为字符串提供吗?

【问题讨论】:

  • 我觉得如果你手动打出来应该没问题
  • Python 不是添加省略号的那个。大概这个逻辑就在inodeshnodes__str__的实现内部。这些变量的类型是什么?
  • inodeshnodesonodes 的变量类型为 int。 lr 是浮点数,wihwho 是浮点数数组

标签: python arrays string


【解决方案1】:

由于声誉问题无法添加 cmets,但您的问题似乎在这里得到了解答:How to print the full NumPy array, without truncation?

底线:

numpy.set_printoptions(threshold=sys.maxsize)

【讨论】:

  • 非常感谢!通过此添加,它可以按预期工作。
  • 我将不胜感激将我的答案标记为已接受的答案;)
  • 很高兴! :)
猜你喜欢
  • 2015-10-21
  • 1970-01-01
  • 2012-03-14
  • 2014-09-08
  • 2020-05-01
  • 2020-02-28
  • 2016-08-17
  • 1970-01-01
相关资源
最近更新 更多