我想從矩陣中洗掉空格
`my_list = range(10, -11, -2) # ???? 3 ?????
import numpy as np
c = np.array(my_list)
cutoff = 0
c[c < cutoff] = -1
print("new arr is:", *c,sep=' ')
import numpy as np
list_of_lists=[1,2,3],[3,2,1],[4,5,6]
matrix=np.array(list_of_lists)
print("Row 2 in matrix:",matrix[1])
import numpy as np
broad=np.full((1,3),2)
matrix=matrix*broad
# list_of_list=matrix.tolist()
# lst1= tr(list_of_list)
# lst2 = lst1.replace("","").replace(",","")
# lst3=lst2[:9] "" lst2[9:17] "" lst2[17:]
print("Broadcasting:",matrix)`
`矩陣列印是 [[ 2 4 6]
[ 6 4 2]
[ 8 10 12]]
我想要 [[2 4 6]
[6 4 2]
[8 10 12]]`
謝謝
uj5u.com熱心網友回復:
您可以使用 repr() 函式回傳字串的可列印表示。
print('Broadcasting:', repr(str(matrix)).replace('\\n ', '').replace(' ', ' '))
這列印:
Broadcasting: '[[ 2 4 6][ 6 4 2][ 8 10 12]]'
uj5u.com熱心網友回復:
numpy 矩陣印刷精美,讓您觀看愉快。您可以通過將其轉換為 python 串列串列并洗掉逗號來強制您想要的輸出:
print_me = str(list(map(list, matrix))).replace(',', '')
print(print_me)
列印:
[[2 4 6] [6 4 2] [8 10 12]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/377958.html
上一篇:如何使用java從串列中的特定物件中添加和減去元素?
下一篇:將物件添加到陣列的函式回傳未定義
