我在Python中使用了列表/數組/矩陣的問題。在列表中添加一個新的列(數組)
我有一個矩陣(或數組,如果需要的話)的列表,我想爲它們中的每一個添加一列(相同數量的行)的新列。我怎樣才能做到這一點??
我有一些事情,並沒有得到任何成功。
感謝您的幫助。
下面是一個例子:
>>> A=[mat([[1,2,3],[4,5,6],[7,8,9]]),mat([[1,0,0],[0,1,0],[0,0,1]])]
>>> A
[matrix([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]), matrix([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])]
使用你們告訴
>>> A = np.hstack((A, np.ones((A.shape[0],1),dtype=A.type)))
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
A = np.hstack((A, np.ones((A.shape[0],1),dtype=A.type)))
AttributeError: 'list' object has no attribute 'shape'`
向我們展示您嘗試過的內容。 – agf