Excuse me if this has been asked previously, I could not find anything.
I am trying to define a function that takes an arbitrary number of .txt files that look like these
reads them, concatenates all the rows and saves it into one numpy array. This works for one .txt file. As soon as i use two files I get array([nan, nan])
as a return, with three files array([nan, nan, nan])
, etc.
import numpy as np
def readInSpectra(*files):
raw = np.genfromtxt(files[0], skip_header=0, delimiter='\t')
for i in range(1, len(files)):
raw_i = np.genfromtxt(files[i], skip_header=0, delimiter='\t')
raw = np.vstack((raw, raw_i))
return raw
files = ('./file1.txt', './file2.txt', './file3.txt')
test = readInSpectra(files)