2013-12-23 40 views
1

我有一個包含numpy矩陣的列表。無論如何,我可以把整個事情變成一個很好的乾淨的numpy數組?python:numpy數組的矩陣列表?

來源:

[matrix([[1]]), matrix([[ 1.99387871]]), matrix([[ 2.53564618]]), matrix([[ 4.39125807]]), matrix([[ 4.246309]]), matrix([[ 5.21571607]]), matrix([[ 6.17408811]]), matrix([[ 4.75146571]]), matrix([[ 6.19319742]]), matrix([[ 6.1277607]]), matrix([[ 7.43821216]])] 

要:

[[1 1.99387871 2.53564618 4.39125807 4.246309 5.21571607 6.17408811 4.75146571 6.19319742 6.1277607 7.43821216]] 

回答

6
b = np.asarray(a, dtype=float) 
#to get the same shape do. 
b = b.reshape(-1, len(b)) 
#to just get one dimmension do. 
b = np.asarray(a, dtype=float).reshape(len(a)) 
+0

釘它!謝謝 –

+1

如果OP關心形狀,可能會添加'.reshape(-1,len(a))'。 – DSM

+0

@DSM謝謝,添加到答案。 – M4rtini