代码笔记~自己实验的时候用的
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import torch
import numpy as np
I=np.eye(4,dtype=float)
RT=[[0.23616787791252136, -0.9717121720314026, 7.4505797087454084e-09, -0.0],
[0.4821586608886719, 0.1171853244304657, 0.868211030960083, 0.0],
[-0.8436513543128967, -0.20504361391067505, 0.49619489908218384, -0.8893723487854004],
[-0.0, 0.0, -0.0, 1.0]]
ww=[0.93344887, 0.16028935, 0.8594594]
w_l2=ww[0]**2 + ww[1]**2 + ww[2]**2
w_0=ww+[0]
w_1=ww+[1]
print(w_0)
#list 转numpy矩阵 将numpy矩阵转torch矩阵类型
w_0=torch.from_numpy(np.array(w_0))
#增加维度
w_0=w_0.unsqueeze(0)
print(w_0)
#矩阵求转置
w_0=w_0.transpose(0,1)
print(w_0)
w_1=torch.from_numpy(np.array(w_1))
w_1=w_1.unsqueeze(0)
print(w_1.shape)
#矩阵的内积
res = torch.mm(w_0,w_1)
print(res)
C_=(2/w_l2)*res
#torch类型矩阵转换测numpy矩阵
C_=C_.numpy()
print(I)
print(C_)
#numpy矩阵的差运算
C_=I-C_
print(C_)
RT=np.array(RT)
print(RT)
#求RT矩阵的逆 RT.I就是求逆
RT_I = np.matrix(RT)
RT_I=RT_I.I
print(RT_I)
#numpy矩阵求内积
CC=np.matmul(RT_I,C_)
print(CC)
M=np.matmul(CC,RT)
print(M)
print(M[0])
A=torch.ones(100)
B=torch.ones(100)
C=torch.ones(100)
A=A.unsqueeze(0)
B=B.unsqueeze(0)
C=C.unsqueeze(0)
meta_data_1=torch.ones(100)
meta_data_1=meta_data_1.unsqueeze(0)
print(meta_data_1.shape)
ress=torch.cat((A,B,C,meta_data_1),0)
#r_es=torch.cat((ress,))
print(ress)
输出结果:
runfile('C:/Users/mayn/.spyder-py3/temp.py', wdir='C:/Users/mayn/.spyder-py3')
[0.93344887, 0.16028935, 0.8594594, 0]
tensor([[0.9334, 0.1603, 0.8595, 0.0000]], dtype=torch.float64)
tensor([[0.9334],
[0.1603],
[0.8595],
[0.0000]], dtype=torch.float64)
torch.Size([1, 4])
tensor([[0.8713, 0.1496, 0.8023, 0.9334],
[0.1496, 0.0257, 0.1378, 0.1603],
[0.8023, 0.1378, 0.7387, 0.8595],
[0.0000, 0.0000, 0.0000, 0.0000]], dtype=torch.float64)
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
[[1.0653936 0.18294655 0.98094558 1.14135186]
[0.18294655 0.03141509 0.16844536 0.1959899 ]
[0.98094558 0.16844536 0.9031913 1.05088304]
[0. 0. 0. 0. ]]
[[-0.0653936 -0.18294655 -0.98094558 -1.14135186]
[-0.18294655 0.96858491 -0.16844536 -0.1959899 ]
[-0.98094558 -0.16844536 0.0968087 -1.05088304]
[ 0. 0. 0. 1. ]]
[[ 2.36167878e-01 -9.71712172e-01 7.45057971e-09 -0.00000000e+00]
[ 4.82158661e-01 1.17185324e-01 8.68211031e-01 0.00000000e+00]
[-8.43651354e-01 -2.05043614e-01 4.96194899e-01 -8.89372349e-01]
[-0.00000000e+00 0.00000000e+00 -0.00000000e+00 1.00000000e+00]]
[[ 2.36167953e-01 4.82158754e-01 -8.43651460e-01 -7.50320280e-01]
[-9.71712348e-01 1.17185335e-01 -2.05043610e-01 -1.82360117e-01]
[ 3.35441456e-09 8.68211244e-01 4.96194986e-01 4.41302100e-01]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00]]
[[ 0.72392302 0.56591475 -0.39455811 -0.22779025]
[ 0.24324174 0.32581401 0.91360761 1.11921529]
[-0.64557653 0.75735456 -0.09821017 -0.25030143]
[ 0. 0. 0. 1. ]]
[[ 0.77669755 -0.55622629 0.29555571 0.12311883]
[-0.55622636 -0.38550975 0.73620275 0.30667794]
[ 0.29555577 0.73620278 0.6088122 -0.16295602]
[ 0. 0. 0. 1. ]]
[[ 0.77669755 -0.55622629 0.29555571 0.12311883]]
torch.Size([1, 100])
tensor([[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]])
三维重建及计算机视觉交流群:
代码技术相关交流群,不定期分享pdf技术相关书籍 !