![](/img/trans.png)
[英]How can I get all strings starting with [ and ending with ] out of a single line using Python?
[英]How can I get a single line out?
eni=soleloge.split(" ")
res = [int(sub.split(':')[1]) for sub in yeni]
這里只有一隊
solmatris=numpy.array(res)
if solmatris.size>0:
print(solmatris)
f.write(solmatrisStr)
這里output如下:
[ 835 732 474 519 831 834 847 852 841 834 801 -9344
-3660 13808 1648 -463 86]
我想出去:
[ 835 732 474 519 831 834 847 852 841 834 801 -9344 -3660 13808 1648 -463 86 ]
轉換為矩陣后,我打印到筆記本上。 我不使用控制台。
https://prnt.sc/10c0m85我不想變成這樣。
我很抱歉一開始沒有清楚地表達我的問題。
為什么它會給出這樣的打印輸出,我該如何修復它。
刪除numpy.array
類型轉換,而是嘗試此print(', '.join(str(r) for r in res))
。
numpy 對 arrays 的表示具有不基於 window 大小的自動環繞。 您可以執行print(*solmatris)
或print(list(solmatris))
以將其放在一行中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.