这取决于你如何设置你的阵列开始。我喜欢使用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列 –