這取決於你如何設置你的陣列開始。我喜歡使用numpy數組,因爲我發現索引容易讓我頭腦發熱。我認爲下面的代碼就是你以後的代碼。因爲你總是有3個colulmns,所以A不需要多長時間,你可以將它分成3列。
import numpy as np
A=np.array([[-0.00022939, -0.04265404, 0.00022939],
[-0.00022939, -0.04265404, 0.00022939],
[0., -0.2096513, 0.],
[0.00026388, 0.00465183, 0.00026388]])
for idx in range(3):
b = A[:, idx]
print b # call your function here
編輯::全面實施顯示代碼&輸出
import numpy as np
def vectors(b):
b = b/np.sqrt(np.sum(b**2.,axis=0))
b = b/np.linalg.norm(b)
z = np.array([0.,0.,1.])
n1 = np.cross(z,b,axis=0)
n1 = n1/np.linalg.norm(n1) ## normalize n
return [n1]
A=np.array([[-0.00022939, -0.04265404, 0.00022939],
[ 0., -0.2096513, 0. ],
[ 0.00026388, 0.00026388, 0.00026388]])
for idx in range(3):
b = A[:, idx]
n1 = vectors(b)
print 'idx', idx, '\nb ', b, '\nn1 ', n1, '\n'
Output:
idx 0
b [-0.00022939 0. 0.00026388]
n1 [array([ 0., -1., 0.])]
idx 1
b [-0.04265404 -0.2096513 0.00026388]
n1 [array([ 0.9799247 , -0.19936794, 0. ])]
idx 2
b [ 0.00022939 0. 0.00026388]
n1 [array([ 0., 1., 0.])]
任何幫助,請! –
我建議你添加一個樣本矩陣'A'並顯示你所期望的結果。請詳細說明你想要的東西。我不明白。 –
@ mr.bjerre,我已經完成了整個矩陣,它有效,但我想使用第一列,然後第二個,...直到n列 –