0

I have many dataset from files to be merged and arranged in one single output file. Here is the example of any two datasets to be merged accordingly.

Data 1 from File 1:
     9.00      2.80     13.08     12.78      0.73
    10.00     -3.44     19.30     18.99      0.14
    12.00      2.60     20.28     20.12      0.39

Data 2 from File 2:
     2.00     -7.73     20.04     18.49      0.62
     5.00     -4.82     17.07     16.38      0.59
     6.00     -2.69     12.55     12.25      0.50
     8.00     -3.85     18.06     17.64      0.94
     9.00     -3.59     16.13     15.73      0.64


Expected output in one file:
 9.00      2.80     13.08     12.78      0.73
10.00     -3.44     19.30     18.99      0.14
12.00      2.60     20.28     20.12      0.39
 2.00     -7.73     20.04     18.49      0.62
 5.00     -4.82     17.07     16.38      0.59
 6.00     -2.69     12.55     12.25      0.50
 8.00     -3.85     18.06     17.64      0.94
 9.00     -3.59     16.13     15.73      0.64

Temporarily the script i used using Python loop for is like this:

import numpy as np
import glob

path='./13-stat-plot-extreme-combine/'
files=glob.glob(path+'13-stat*.dat')

for x in range(len(files)):
    file1=files[x]
    data1=np.loadtxt(file1)

np.savetxt("Combine-Stats.dat",data1,fmt='%9.2f')

The problem is only one dataset is saved on that new file. Question how to use concatenate to such case at different axis dataset?

1 Answer 1

1

Like this:

arrays = [np.loadtxt(name) for name in files]
combined = np.concatenate(arrays)
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome!..problem solved. Thanks a lot. Enjoy your Sunday.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.