打印不带括号的Numpy数组 [英] Printing Numpy arrays without brackets
本文介绍了打印不带括号的Numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
predictions = [x6,x5,x4,x3,x2,x1]
predictions
调用上面的列表将产生以下数组:
Calling the above list yields the following arrays:
[array([782.36739152]),
array([783.31415872]),
array([726.90474426]),
array([772.08910103]),
array([728.79734162]),
array([753.67887657])]
但是我只想打印或调用内部的数字,数字周围没有数组或方括号.
Yet I would like to print or call just the numbers inside, no array or brackets around the numbers.
使用下面的函数可以将数字干净地保存为CSV,但是我不想保存数字,我想在iPython中调用它们:
Using the function below cleanly saves just the numbers to CSV, but I DON'T want to save the numbers, I want to call them inside iPython:
np.savetxt("P:/Earnest/Old/R/OutputPython.csv", predictions, delimiter=",")
我该如何实现?
推荐答案
如果将predictions
更改为numpy
数组,则可以使用print(*predictions.flatten(), sep=', ')
.
If you change predictions
to numpy
array then, you can use print(*predictions.flatten(), sep=', ')
.
您可以尝试以下操作:
import numpy as np
predictions = np.array([np.array([782.36739152]),
np.array([783.31415872]),
np.array([726.90474426]),
np.array([772.08910103]),
np.array([728.79734162]),
np.array([753.67887657])])
print(*predictions.flatten(), sep=', ')
输出:
782.36739152, 783.31415872, 726.90474426, 772.08910103, 728.79734162, 753.67887657
这篇关于打印不带括号的Numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文