Python 矩阵中 求每行个别列的norm值,然后再求所有行的norm总和

taux_with_orthese=[]
with open('tau_mannequin_1432139027.txt') as f:
for line in f.readlines():
taux_with_orthese.append(map(float,line.replace("\n","").split(",")))
taux_with_orthese = np.array(taux_with_orthese)

tau_norm_instant = []
print tau_norm_instant
for i in range(0,len(taux_with_orthese)-1):

tau_norm_instant = np.array([np.sqrt((taux_with_orthese[i][28])**2 + (taux_with_orthese[i][29])**2 +(taux_with_orthese[i][30])**2 + (taux_with_orthese[i][31])**2 + (taux_with_orthese[i][32])**2 + (taux_with_orthese[i][33])**2+
(taux_with_orthese[i][34])**2)])
print tau_norm_instant
程序这么写完之后 只出现一列数

,我想求这一列数的和 怎么求呢?试过 tau_norm_instant = sum(
np.array([np.sqrt((taux_with_orthese[i][28])**2 + (taux_with_orthese[i][29])**2 +
(taux_with_orthese[i][30])**2 + (taux_with_orthese[i][31])**2 + (taux_with_orthese[i][32])**2 + (taux_with_orthese[i][33])**2 +(taux_with_orthese[i][34])**2)])),但是不好使啊...

没看懂公式  不过凭经验。。。

tau_norm_instant = np.zero(1)
for i in range(0,len(taux_with_orthese)-1):
        tau_norm_instant += np.array([np.sqrt((taux_with_orthese[i][28])**2 + (taux_with_orthese[i][29])**2                                                                +(taux_with_orthese[i][30])**2 + (taux_with_orthese[i][31])**2 +                                                                  (taux_with_orthese[i][32])**2 + (taux_with_orthese[i][33])**2+
                                                                (taux_with_orthese[i][34])**2)])
                                                                
print tau_norm_instant

追问

谢谢!最后一个就是我要求的值。但是我怎么能提取出来呢...因为还要做别的计算

温馨提示:答案为网友推荐,仅供参考
相似回答