【发布时间】:2019-04-25 14:30:53
【问题描述】:
我有 csv 文件,每行枚举一个 4x4 矩阵,每个文件超过 300 行。 我想用 [0,0,0,1] 将每个 4x4 矩阵 numpy.multiply 我尝试使用 numpy.array、numpy.matrix 等进行转换,也尝试更改原始符号但无济于事。 我要处理的行的格式:
camera1="[['9.5820988666217111e-001','1.8364288924172481e-002','2.8547603401192861e-001','-1.0076250938522580e+001'],['-1.7086800960614995e-001','-7.6361969781499617e-001','6.2264683441110236e-001','-4.5906868751556480e+001'],['2.2942958919045936e-001','-6.4540507435349748e-001','-7.2857007460000278e-001','2.1664174288937179e+001'],['0.0000000000000000e+000','0.0000000000000000e+000','0.0000000000000000e+000','1.0000000000000000e+000']]"
我有点困惑矩阵和数组在 numpy 方面的区别以及我应该使用哪个。我想为每一行实现的是产品
9.58209887e-01 1.83642889e-02 2.85476034e-01 -1.00762509e+01
-1.70868010e-01 -7.63619698e-01 6.22646834e-01 -4.59068688e+01
2.29429589e-01 -6.45405074e-01 -7.28570075e-01 2.16641743e+01
0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00
乘以
0,0,0,1,
获得
[[0.0,0.0,0.0,-10.07625094],
[ -0.0,-0.0,0.0,-45.90686875],
[0.0,-0.0,-0.0,21.66417429],
[0.0,0.0,0.0,1.0]]
但我只收到未实施之类的错误。 有什么线索吗?
这将是我的 python 脚本:
import numpy as nm
def getCoord(fila):
#lee la línea y extrae las coordenadas XYZ
vect=fila.split('=')
print (vect)
camID=vect[0]
trMatrix=vect[1]
b=[0,0,0,1]
crs=nm.multiply(trMatrix,b)[0:3]
return camid,crs
unFichero=r"docmatrix.txt"
with open('outfile.csv', 'w') as f:
f.write(r"camera,coorx,coory,coorz")
with open(unFichero) as infile:
transf=getCoord(infile.read())
f.write(transf[0]+","+transf[1]+'\n')
【问题讨论】:
标签: string file numpy matrix-multiplication scientific-notation