我有3个不同的.txt文件,每个文件都包含x,y,z
坐标,例如:
我阅读了这3个文件的内容:
inputFileList = sorted(glob.glob(inputSourceDir + '/*.txt'), key=lambda x: (int(re.sub('\D', '', x)), x))
inputFileList = inputFileList[0:100]
inputTotalDataList = []
self.numberOfInputFiles = 0
for inputFilePath in inputFileList:
inputDataInFile = np.genfromtxt(inputFilePath, dtype=float, delimiter=',') # usecols= 0
baseWithExt = os.path.basename(inputFilePath)
base = os.path.splitext(baseWithExt)[0]
inputTotalDataList.append(inputDataInFile)
self.numberOfInputFiles = self.numberOfInputFiles + 1
self.inputTotalData = np.array(inputTotalDataList)
self.inputTotalData = self.inputTotalData.reshape(self.numberOfInputFiles * len(inputDataInFile), 3)
print('TotalData: ', inputTotalData )
作为输出,我得到:
TotalData: [[ 7.29948 -187.854 760.208 ]
[ -41.2607 -188.068 761.008 ]
[ -13.2162 -193.675 771.235 ]
[ 35.361 -185.632 776.405 ]
[ -58.8706 -188.025 785.184 ]
[ 12.8998 -196.275 789.446 ]
[ -27.303 -198.127 791.598 ]
[ -48.8703 -195.487 812.969 ]
[ 30.4976 -192.05 818.794 ]]
但是我想代表每个读取的文件,例如:
[[ 7.29948 -187.854 760.208 ]
[ -41.2607 -188.068 761.008 ]
[ -13.2162 -193.675 771.235 ]]
[[ 35.361 -185.632 776.405 ]
[ -58.8706 -188.025 785.184 ]
[ 12.8998 -196.275 789.446 ]]
[[ -27.303 -198.127 791.598 ]
[ -48.8703 -195.487 812.969 ]
[ 30.4976 -192.05 818.794 ]]
。 。
如何将我的输出转换成上面想要的结果?
答案 0 :(得分:2)
代替
self.inputTotalData = self.inputTotalData.reshape(self.numberOfInputFiles * len(inputDataInFile), 3)
使用所需的内部形状(3x3)并推断出第一(外部)尺寸
self.inputTotalData = self.inputTotalData.reshape(-1, 3, 3)