Change the output result of np.array

Multi tool use


Change the output result of np.array
I have 3 different .txt files and each of them contains x,y,z
coordinates such:
I read the content of those 3 files:
x,y,z
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 )
As output I get:
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 ]]
But I want to represent each read file like:
[[ 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 ]]
.
.
.
How can I convert my output to the desired result above?
reshape
self.inputTotalData
1 Answer
1
Instead of
self.inputTotalData = self.inputTotalData.reshape(self.numberOfInputFiles * len(inputDataInFile), 3)
use the desired inner shape (3x3) and let it deduce the first (outer) dimension
self.inputTotalData = self.inputTotalData.reshape(-1, 3, 3)
Can I also convert that
self.inputTotalData np.array
to dict
after reshaping?– mystic.06
1 hour ago
self.inputTotalData np.array
dict
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Is your indentation off? (e.g. the last 3 lines?). What's the purpose of the
reshape
line? Did you checkself.inputTotalData
before that?– hpaulj
5 mins ago