我想在numpy中構建一個矩陣。矩陣的尺寸應該是(5001x7)。這裏是我的代碼:構建一個numpy矩陣
S=np.array([.0788,.0455,.0222,.0042,.0035,.0029,.0007])
#This is vector S, comprised of 7 scalars.
lamb=list(range(0,5001))
#This is a list of possible values for lambda, a parameter in my data.
M = np.empty([5001,7], order='C')
#This is the empty matrix which is to be filled in the iterations below.
for i in S:
for j in lamb:
np.append(M,((S[i]**2)/(lamb[j]+S[i]**2)))
我遇到的問題是,M仍然是零矢量矩陣。
重要的細節: 1)我已經分配最後的路線爲:
M=np.append(M,((S[i]**2)/(lamb[j]+S[i]**2)))
我然後在一維數組得到長度70014的值的陣列。我不確定該怎麼做。
2)我已經嘗試了矩陣M.
3)I收到此警告切換「浮動」和「INT」之間的D型細胞參數,當我運行的代碼: VisibleDeprecationWarning:使用非整數而不是整數會導致錯誤的未來 app.launch_new_instance()
4)我在Python 3.4
工作,我真的很感謝你的幫助。謝謝!
我不認爲'np.append'是做什麼的,你覺得它在做什麼。 –