前提
数据源是六轴IMU的采集数据
image-20210918174522504.pngStep 1 open() 打开文件存成二维数组
from pandas import read_csv
def readCSV(path=None):
dataframe = read_csv(r"F:\skateboard_2\subject01\algo_material\arranged_files_step2\IMU_shank\01_102412.csv", header=0, delim_whitespace=None)
dataframe = np.array(dataframe[:100]) # 读取前一百行
print(dataframe.shape)
return dataframe
if __name__ == '__main__':
aa = readCSV()
"""
(100, 6)
"""
Step 2 把多个二维数组进行拼接
场景:==单个IMU==的情况下,把单个 (100,6) 的矩阵看作是一个样本,而我们有很多个样本,以下举例为3个样本,拼接在一起成 (3,100,6) 的大矩阵,要怎么做?
答:利用 np.concatenate()
函数
参考博客:https://blog.csdn.net/guofei_fly/article/details/85485173
from pandas import read_csv
from numpy import concatenate
import numpy as np
# step1
def readCSV(path=None):
dataframe = read_csv(r"F:\skateboard_2\subject01\algo_material\arranged_files_step2\IMU_shank\01_102412.csv", header=0, delim_whitespace=None)
dataframe = np.array(dataframe[:100]) # 读取前一百行
print(dataframe.shape)
return dataframe
# step2
def combineMat(tupleList):
res = concatenate(tupleList, axis=0)
print(cc.shape)
return res
if __name__ == '__main__':
aa = readCSV()
bb = readCSV()
cc = readCSV()
dd = combineMat(([aa], [bb], [cc]))
"""
(100, 6)
(100, 6)
(100, 6)
(3,100, 6)
"""
Step 3 4个IMU的情况,拼接成 (10,4,100,6)
错误操作:aa = [aa for i in range(10)]
,并不能把得到 (10, 1, 100, 6) 矩阵格式
from pandas import read_csv
from numpy import concatenate
import numpy as np
# step1
def readCSV(path=None):
dataframe = read_csv(r"F:\skateboard_2\subject01\algo_material\arranged_files_step2\IMU_shank\01_102412.csv",
header=0, delim_whitespace=None)
dataframe = np.array(dataframe[:100]) # 读取前一百行
print(dataframe.shape)
return dataframe
# step2
def combineMat(tupleList):
res = concatenate(tupleList, axis=0)
print(cc.shape)
return res
if __name__ == '__main__':
aa = readCSV()
bb = readCSV()
cc = readCSV()
aa = [aa for i in range(10)]
print(np.array(aa).shape)
"""
(10,100, 6)
"""
正确操作:aa = [[aa] for i in range(10)]
from pandas import read_csv
from numpy import concatenate
import numpy as np
# step1
def readCSV(path=None):
dataframe = read_csv(path,
header=0, delim_whitespace=None)
dataframe = np.array(dataframe[:100]) # 读取前一百行
print(dataframe.shape)
return dataframe
# step2
def combineMat(tupleList):
res = concatenate(tupleList, axis=0)
print(cc.shape)
return res
if __name__ == '__main__':
aa = readCSV(r"F:\ProjectAurora\实验材料与数据存放\实验材料\Transformer资料\HARDataset\train\Inertial Signals\body_acc_y_train.txt")
bb = readCSV(r"F:\ProjectAurora\实验材料与数据存放\实验材料\Transformer资料\HARDataset\train\Inertial Signals\body_acc_y_train.txt")
cc = readCSV(r"F:\ProjectAurora\实验材料与数据存放\实验材料\Transformer资料\HARDataset\train\Inertial Signals\body_acc_y_train.txt")
aaa = [[aa] for i in range(10)]
bbb = [[bb] for i in range(10)]
ccc = [[cc] for i in range(10)]
ddd = concatenate((aaa, bbb, ccc), axis=1) # axis是从左到右开始算,0 1 2 3 对应 (10,1,100,1)
print(ddd.shape)
# dd = combineMat(([aa], [bb], [cc]))
"""
(10,3,100, 1)
"""
网友评论