0
$\begingroup$

I have a lot of '.txt' (pre-processed) files related to C3D and I need to use this to train and test while using CNN model.

How does one go about this?

Most of data in each .txt files are formatted like this:

{0.00001478 0.00000006 0.00000133 0.00000038 0.00000001 0.00000001 0.00000000 0.00000001 0.00000004 0.00000011 0.00000000 0.00000002 0.00095226 0.00005343 0.00000002 0.00000000 0.00000000 0.00000342 0.00000002 0.00000036 0.00000000 0.00000046 0.00000000 0.00000000 0.00001069 0.00000000 0.00007515 0.00000000 0.00000000 0.00000000 0.00000000 0.00000009 0.00000000 0.01169860 0.00000017 0.00000000 0.00000010 0.00000113 0.00000472 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000003 0.00000150 0.00001475 0.00000000 0.00000000 0.00000023 0.00000005 0.00000011 0.00000000 0.00000000 0.00001333 0.00000000 0.00000002 0.00000017 0.00000076 0.00000051 0.00000015 0.00000440 0.00000001 0.00000079 0.00000000 0.00000000 0.00000008 0.00000000 0.00000001 0.00000002 0.98503888 0.00000013 0.00000000 0.00000000 0.00208691 0.00000000 0.00000003 0.00000051 0.00000001 0.00001191 0.00000000 0.00000000 0.00000001 0.00000001 0.00000000 0.00000000 0.00000003 0.00000000 0.00000001 0.00000000 0.00000000 0.00000021 0.00000000 0.00000000 0.00000000 0.00000000 0.00000027 0.00000675}
$\endgroup$
2
  • $\begingroup$ Welcome to DS.SE! It would be useful to show the format of the .txt data. $\endgroup$ Apr 24, 2019 at 10:25
  • $\begingroup$ I've added the format. $\endgroup$ Apr 24, 2019 at 11:17

1 Answer 1

0
$\begingroup$

I did not really feel clear on what you were trying to accomplish. But here is how you load the format you showed into a numpy array:

import numpy as np

# Read file from disk
with open('path/to/file.txt') as f:
    txt = f.read()

# Make a list of values in string format 
vals = txt.replace('{','').replace('}','').strip().split()

# Cast values to floats
vals = [np.float32(val) for val in vals]

# Store in numpy array
vals = np.array(vals)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.