2017-07-04 124 views
0

我有以下Python代碼來顯示矩陣元素,但它沒有顯示預期的結果,因爲我想顯示第一個元素而不是第一個線元素。問題是什麼?Python中二維矩陣的元素

import numpy as np 

ss = [-0.115, -0.052, 0.559, -0.344, 0.077, 0.032, -0.017, -0.035] 
sx = np.matrix([[ss[0],ss[1],ss[2],ss[3]],[ss[4],ss[5],ss[6],ss[7]]]) 

print('s0=', sx[0]) 
print('s00=', sx[0][0]) 

回答

0

對於在2D陣列

print('s0=', sx[0,:])) # replace zero with row you want to access 

並訪問第一元件訪問第一行。

print('s00=', sx.item(0,0)) # replace 0,0 with the position of element 

對於文檔refer

+0

非常感謝。 – spices